Skip to content

Commit 03f693b

Browse files
castastrophepfulton
andcommitted
refactor(asset)!: migrate to tokens package (#2553)
BREAKING CHANGE: migrates to use spectrum-tokens * refactor(asset): migrate to tokens package * chore: add mods values for customization --------- Co-authored-by: Patrick Fulton <[email protected]>
1 parent 5f365eb commit 03f693b

File tree

5 files changed

+75
-34
lines changed

5 files changed

+75
-34
lines changed

components/asset/gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = require("@spectrum-css/component-builder");
1+
module.exports = require("@spectrum-css/component-builder-simple");

components/asset/index.css

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,63 @@ governing permissions and limitations under the License.
1111
*/
1212

1313
.spectrum-Asset {
14-
inline-size: 100%;
15-
block-size: 100%;
1614
display: flex;
1715
align-items: center;
1816
justify-content: center;
17+
18+
inline-size: 100%;
19+
block-size: 100%;
1920
}
2021

2122
.spectrum-Asset-image {
2223
max-inline-size: 100%;
2324
max-block-size: 100%;
2425
object-fit: contain;
25-
transition: opacity var(--spectrum-global-animation-duration-100);
26+
transition: opacity var(--spectrum-animation-duration-100);
2627
}
2728

2829
.spectrum-Asset-folder,
2930
.spectrum-Asset-file {
30-
inline-size: 100%;
31+
inline-size: clamp(
32+
var(--mod-asset-icon-min-width, 48px),
33+
100%,
34+
var(--mod-asset-icon-max-width, 80px)
35+
);
3136
block-size: 100%;
32-
min-inline-size: var(--spectrum-asset-icon-min-width);
33-
max-inline-size: var(--spectrum-asset-icon-max-width);
34-
margin: var(--spectrum-asset-icon-margin);
37+
margin: var(--mod-asset-icon-margin, 20px);
3538
}
3639

3740
.spectrum-Asset-folderBackground {
38-
fill: var(--highcontrast-asset-folder-background-color, var(--spectrum-asset-folder-background-color));
41+
fill: var(
42+
--highcontrast-asset-folder-background-color,
43+
var(
44+
--mod-asset-folder-background-color,
45+
var(--spectrum-gray-300)
46+
)
47+
);
3948
}
4049

4150
.spectrum-Asset-fileBackground {
42-
fill: var(--highcontrast-asset-file-background-color, var(--spectrum-asset-file-background-color));
51+
fill: var(
52+
--highcontrast-asset-file-background-color,
53+
var(
54+
--mod-asset-file-background-color,
55+
var(--spectrum-gray-50)
56+
)
57+
);
4358
}
4459

4560
.spectrum-Asset-folderOutline,
4661
.spectrum-Asset-fileOutline {
47-
fill: var(--spectrum-asset-icon-outline-color);
62+
fill: var(
63+
--mod-asset-icon-outline-color,
64+
var(--spectrum-gray-500)
65+
);
4866
}
4967

5068
@media (forced-colors: active) {
51-
.spectrum-Asset {
69+
.spectrum-Asset {
5270
--highcontrast-asset-folder-background-color: currentColor;
5371
--highcontrast-asset-file-background-color: currentColor;
54-
}
72+
}
5573
}

components/asset/metadata/mods.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
| Modifiable custom properties |
2+
| ------------------------------------- |
3+
| `--mod-asset-file-background-color` |
4+
| `--mod-asset-folder-background-color` |
5+
| `--mod-asset-icon-margin` |
6+
| `--mod-asset-icon-max-width` |
7+
| `--mod-asset-icon-min-width` |
8+
| `--mod-asset-icon-outline-color` |

components/asset/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"main": "dist/index-vars.css",
1717
"peerDependencies": {
18-
"@spectrum-css/vars": ">=9"
18+
"@spectrum-css/tokens": ">=13"
1919
},
2020
"publishConfig": {
2121
"access": "public"
Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
// Import the component markup template
1+
import { html } from "lit";
2+
import { styleMap } from "lit/directives/style-map.js";
3+
24
import { Template } from "./template";
35

6+
/**
7+
* Use an asset element to visually represent a file, folder or image. File and folder representations will center themselves horizontally and vertically in the space provided to the element. Images will be contained to the element, growing to the element's full height while centering itself within the width provided.
8+
*/
49
export default {
510
title: "Components/Asset",
6-
description:
7-
"Use an asset element to visually represent a file, folder or image. File and folder representations will center themselves horizontally and vertically in the space provided to the element. Images will be contained to the element, growing to the element's full height while centering itself within the width provided.",
811
component: "Asset",
912
argTypes: {
1013
reducedMotion: { table: { disable: true } },
14+
scale: {
15+
name: "Platform scale",
16+
if: { arg: "preset", neq: "image" }
17+
},
1118
preset: {
1219
name: "Preset asset types",
1320
type: { name: "string" },
1421
table: {
1522
type: { summary: "string" },
1623
category: "Component",
1724
},
18-
options: ["folder", "file"],
25+
options: ["folder", "file", "image"],
1926
control: "select",
2027
},
2128
image: {
@@ -26,33 +33,41 @@ export default {
2633
category: "Component",
2734
},
2835
control: { type: "file", accept: ".svg,.png,.jpg,.jpeg,.webc" },
36+
if: { arg: "preset", eq: "image" }
2937
},
3038
},
3139
args: {
3240
rootClass: "spectrum-Asset",
41+
preset: "image",
42+
image: "example-ava.png",
3343
},
3444
parameters: {
3545
status: {
3646
type: process.env.MIGRATED_PACKAGES.includes("asset")
3747
? "migrated"
38-
: undefined,
48+
: "legacy",
3949
},
4050
},
4151
};
4252

43-
export const SymbolicAsset = Template.bind({});
44-
SymbolicAsset.argTypes = {
45-
image: { table: { disable: true } },
46-
};
47-
SymbolicAsset.args = {
48-
preset: "folder",
49-
};
53+
const AssetGroup = (args) => html`
54+
${window.isChromatic() ? html`
55+
<div style=${styleMap({
56+
display: "grid",
57+
gridTemplateColumns: "repeat(3, 200px)",
58+
gap: "8px"
59+
})}>
60+
${Template(args)}
61+
${Template({
62+
...args,
63+
preset: "file",
64+
})}
65+
${Template({
66+
...args,
67+
preset: "folder",
68+
})}
69+
</div>
70+
` : Template(args)}
71+
`;
5072

51-
export const ImageAsset = Template.bind({});
52-
ImageAsset.argTypes = {
53-
preset: { table: { disable: true } },
54-
scale: { table: { disable: true } },
55-
};
56-
ImageAsset.args = {
57-
image: "example-ava.png",
58-
};
73+
export const Default = AssetGroup.bind({});

0 commit comments

Comments
 (0)