@graphprotocol/gds-css 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -0
- package/dist/component-registry.d.ts +90 -0
- package/dist/component-registry.d.ts.map +1 -0
- package/dist/component-registry.js +93 -0
- package/dist/component-registry.js.map +1 -0
- package/dist/css-props/getCSSPropRawValue.d.ts +4 -0
- package/dist/css-props/getCSSPropRawValue.d.ts.map +1 -0
- package/dist/css-props/getCSSPropRawValue.js +41 -0
- package/dist/css-props/getCSSPropRawValue.js.map +1 -0
- package/dist/css-props/index.d.ts +5 -0
- package/dist/css-props/index.d.ts.map +1 -0
- package/dist/css-props/index.js +5 -0
- package/dist/css-props/index.js.map +1 -0
- package/dist/css-props/parseCSSPropValue.d.ts +7 -0
- package/dist/css-props/parseCSSPropValue.d.ts.map +1 -0
- package/dist/css-props/parseCSSPropValue.js +70 -0
- package/dist/css-props/parseCSSPropValue.js.map +1 -0
- package/dist/css-props/registerCSSProps.d.ts +7 -0
- package/dist/css-props/registerCSSProps.d.ts.map +1 -0
- package/dist/css-props/registerCSSProps.js +231 -0
- package/dist/css-props/registerCSSProps.js.map +1 -0
- package/dist/css-props/types.d.ts +29 -0
- package/dist/css-props/types.d.ts.map +1 -0
- package/dist/css-props/types.js +2 -0
- package/dist/css-props/types.js.map +1 -0
- package/dist/css-states/index.d.ts +3 -0
- package/dist/css-states/index.d.ts.map +1 -0
- package/dist/css-states/index.js +3 -0
- package/dist/css-states/index.js.map +1 -0
- package/dist/css-states/registerCSSStates.d.ts +23 -0
- package/dist/css-states/registerCSSStates.d.ts.map +1 -0
- package/dist/css-states/registerCSSStates.js +119 -0
- package/dist/css-states/registerCSSStates.js.map +1 -0
- package/dist/css-states/states.d.ts +71 -0
- package/dist/css-states/states.d.ts.map +1 -0
- package/dist/css-states/states.js +140 -0
- package/dist/css-states/states.js.map +1 -0
- package/dist/design-tokens.generated.d.ts +1167 -0
- package/dist/design-tokens.generated.d.ts.map +1 -0
- package/dist/design-tokens.generated.js +2675 -0
- package/dist/design-tokens.generated.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/tailwind-customizations/index.d.ts +3 -0
- package/dist/tailwind-customizations/index.d.ts.map +1 -0
- package/dist/tailwind-customizations/index.js +3 -0
- package/dist/tailwind-customizations/index.js.map +1 -0
- package/dist/tailwind-customizations/registerUtilities.d.ts +9 -0
- package/dist/tailwind-customizations/registerUtilities.d.ts.map +1 -0
- package/dist/tailwind-customizations/registerUtilities.js +59 -0
- package/dist/tailwind-customizations/registerUtilities.js.map +1 -0
- package/dist/tailwind-customizations/registerVariants.d.ts +8 -0
- package/dist/tailwind-customizations/registerVariants.d.ts.map +1 -0
- package/dist/tailwind-customizations/registerVariants.js +197 -0
- package/dist/tailwind-customizations/registerVariants.js.map +1 -0
- package/dist/tailwind-customizations/variants.d.ts +72 -0
- package/dist/tailwind-customizations/variants.d.ts.map +1 -0
- package/dist/tailwind-customizations/variants.js +153 -0
- package/dist/tailwind-customizations/variants.js.map +1 -0
- package/dist/tailwind-plugin.d.ts +4 -0
- package/dist/tailwind-plugin.d.ts.map +1 -0
- package/dist/tailwind-plugin.js +12 -0
- package/dist/tailwind-plugin.js.map +1 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/cssUnescape.d.ts +20 -0
- package/dist/utils/cssUnescape.d.ts.map +1 -0
- package/dist/utils/cssUnescape.js +44 -0
- package/dist/utils/cssUnescape.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/pxToTw.d.ts +3 -0
- package/dist/utils/pxToTw.d.ts.map +1 -0
- package/dist/utils/pxToTw.js +5 -0
- package/dist/utils/pxToTw.js.map +1 -0
- package/dist/utils/twToPx.d.ts +3 -0
- package/dist/utils/twToPx.d.ts.map +1 -0
- package/dist/utils/twToPx.js +5 -0
- package/dist/utils/twToPx.js.map +1 -0
- package/dist/utils/twToRem.d.ts +3 -0
- package/dist/utils/twToRem.d.ts.map +1 -0
- package/dist/utils/twToRem.js +5 -0
- package/dist/utils/twToRem.js.map +1 -0
- package/dist/utils/wrapSelector.d.ts +10 -0
- package/dist/utils/wrapSelector.d.ts.map +1 -0
- package/dist/utils/wrapSelector.js +57 -0
- package/dist/utils/wrapSelector.js.map +1 -0
- package/package.json +65 -0
- package/src/component-registry.ts +213 -0
- package/src/css-props/getCSSPropRawValue.ts +52 -0
- package/src/css-props/index.ts +4 -0
- package/src/css-props/parseCSSPropValue.ts +81 -0
- package/src/css-props/registerCSSProps.ts +274 -0
- package/src/css-props/types.ts +35 -0
- package/src/css-states/index.ts +2 -0
- package/src/css-states/registerCSSStates.ts +136 -0
- package/src/css-states/states.ts +160 -0
- package/src/design-tokens.generated.ts +2799 -0
- package/src/index.ts +6 -0
- package/src/tailwind-customizations/index.ts +2 -0
- package/src/tailwind-customizations/registerUtilities.ts +65 -0
- package/src/tailwind-customizations/registerVariants.ts +296 -0
- package/src/tailwind-customizations/variants.ts +190 -0
- package/src/tailwind-plugin.ts +14 -0
- package/src/types.ts +4 -0
- package/src/utils/cssUnescape.ts +49 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/pxToTw.ts +4 -0
- package/src/utils/twToPx.ts +4 -0
- package/src/utils/twToRem.ts +4 -0
- package/src/utils/wrapSelector.ts +60 -0
- package/styles/fonts/EuclidCircularA-Bold.woff2 +0 -0
- package/styles/fonts/EuclidCircularA-BoldItalic.woff2 +0 -0
- package/styles/fonts/EuclidCircularA-Light.woff2 +0 -0
- package/styles/fonts/EuclidCircularA-LightItalic.woff2 +0 -0
- package/styles/fonts/EuclidCircularA-Medium.woff2 +0 -0
- package/styles/fonts/EuclidCircularA-MediumItalic.woff2 +0 -0
- package/styles/fonts/EuclidCircularA-Regular.woff2 +0 -0
- package/styles/fonts/EuclidCircularA-RegularItalic.woff2 +0 -0
- package/styles/fonts/EuclidCircularA-Semibold.woff2 +0 -0
- package/styles/fonts/EuclidCircularA-SemiboldItalic.woff2 +0 -0
- package/styles/fonts.css +83 -0
- package/styles/global.css +203 -0
- package/styles/layers.css +8 -0
- package/styles/tailwind.css +13 -0
- package/styles/tailwind.vscode.css +11 -0
- package/styles/theme.css +420 -0
- package/styles/typography.css +198 -0
- package/styles/utilities.css +305 -0
- package/styles/variants.css +34 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import cssesc from 'cssesc';
|
|
2
|
+
import { parseNumber } from '@graphprotocol/gds-utils';
|
|
3
|
+
import { getRegisteredComponent, getRegisteredComponents, } from "../component-registry.js";
|
|
4
|
+
import { getCSSPropRawValue } from "./getCSSPropRawValue.js";
|
|
5
|
+
/**
|
|
6
|
+
* Registers CSS Props functionality in the Tailwind plugin. This includes custom properties,
|
|
7
|
+
* utilities, and variants for prop-based styling.
|
|
8
|
+
*/
|
|
9
|
+
export function registerCSSProps(api) {
|
|
10
|
+
const componentsByCSSProp = getRegisteredComponents(true).reduce((outerMap, component) => {
|
|
11
|
+
for (const cssProp of Object.values(component.cssProps)) {
|
|
12
|
+
const innerMap = outerMap.get(cssProp.kebabName) ??
|
|
13
|
+
outerMap.set(cssProp.kebabName, new Map()).get(cssProp.kebabName);
|
|
14
|
+
innerMap.set(component.kebabName, component);
|
|
15
|
+
}
|
|
16
|
+
return outerMap;
|
|
17
|
+
}, new Map());
|
|
18
|
+
const cssPropKebabNames = [...componentsByCSSProp.keys()];
|
|
19
|
+
/** Register a couple non-inherited custom properties for each prop name. */
|
|
20
|
+
for (const cssPropKebabName of cssPropKebabNames) {
|
|
21
|
+
api.addBase({
|
|
22
|
+
[`@property --gds-default-${cssPropKebabName}`]: {
|
|
23
|
+
syntax: "'*'",
|
|
24
|
+
inherits: 'false',
|
|
25
|
+
},
|
|
26
|
+
[`@property --gds-passed-${cssPropKebabName}`]: {
|
|
27
|
+
syntax: "'*'",
|
|
28
|
+
inherits: 'false',
|
|
29
|
+
},
|
|
30
|
+
[`@property --gds-prop-${cssPropKebabName}`]: {
|
|
31
|
+
syntax: "'*'",
|
|
32
|
+
inherits: 'false',
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** Register a custom property for each component-prop pair to restrict the allowed values. */
|
|
37
|
+
for (const component of getRegisteredComponents()) {
|
|
38
|
+
for (const cssProp of Object.values(component.cssProps)) {
|
|
39
|
+
const syntax = (() => {
|
|
40
|
+
switch (cssProp.type) {
|
|
41
|
+
case 'values':
|
|
42
|
+
return `'${cssProp.values.map((value) => getCSSPropRawValue(cssProp, value)).join(' | ')}'`;
|
|
43
|
+
case 'string':
|
|
44
|
+
return "'<string>'";
|
|
45
|
+
case 'number':
|
|
46
|
+
return "'<number>'";
|
|
47
|
+
case 'length':
|
|
48
|
+
return "'<length-percentage>'";
|
|
49
|
+
case 'color':
|
|
50
|
+
return "'<color>'";
|
|
51
|
+
default:
|
|
52
|
+
return "'*'";
|
|
53
|
+
}
|
|
54
|
+
})();
|
|
55
|
+
api.addBase({
|
|
56
|
+
[`@property --gds-${component.kebabName}-${cssProp.kebabName}`]: {
|
|
57
|
+
syntax,
|
|
58
|
+
/**
|
|
59
|
+
* We only need this property to inherit if the type is not `values`, because `values` CSS
|
|
60
|
+
* props are accessed via style queries.
|
|
61
|
+
*/
|
|
62
|
+
inherits: cssProp.type === 'values' ? 'false' : 'true',
|
|
63
|
+
'initial-value': (() => {
|
|
64
|
+
if (cssProp.type === 'length' &&
|
|
65
|
+
typeof cssProp.initialValue === 'string' &&
|
|
66
|
+
/(cap|ch|em|ex|ic|lh)$/.test(cssProp.initialValue)) {
|
|
67
|
+
// `initial-value` cannot be font-size-relative
|
|
68
|
+
return '100%';
|
|
69
|
+
}
|
|
70
|
+
return getCSSPropRawValue(cssProp, cssProp.initialValue);
|
|
71
|
+
})(),
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Base styles for each component, including defining the default value of each CSS prop and
|
|
77
|
+
* applying the value passed via the React prop, if any. See `getCSSPropsAttributes` for details
|
|
78
|
+
* on how each prop type is handled.
|
|
79
|
+
*/
|
|
80
|
+
api.addBase({
|
|
81
|
+
'@layer components': {
|
|
82
|
+
[`.${component.className}`]: {
|
|
83
|
+
'--tw-sort': 'container-type',
|
|
84
|
+
...(component.containerName ? { 'container-name': component.containerName } : {}),
|
|
85
|
+
...Object.values(component.cssProps).reduce((rules, cssProp) => {
|
|
86
|
+
return {
|
|
87
|
+
...rules,
|
|
88
|
+
[`--gds-passed-or-default-${cssProp.kebabName}`]: `var(--gds-passed-${cssProp.kebabName}, var(--gds-default-${cssProp.kebabName}, ${getCSSPropRawValue(cssProp, cssProp.initialValue)}))`,
|
|
89
|
+
[`--gds-${component.kebabName}-${cssProp.kebabName}`]: `var(--gds-prop-${cssProp.kebabName}, var(--gds-passed-or-default-${cssProp.kebabName}))`,
|
|
90
|
+
};
|
|
91
|
+
}, {}),
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function parseBareValueNumber(bareValue, increment = 0.25) {
|
|
97
|
+
const number = parseNumber(bareValue, { strict: true });
|
|
98
|
+
if (number === null || number < 0 || !Number.isInteger(number * (1 / increment)))
|
|
99
|
+
return null;
|
|
100
|
+
return number;
|
|
101
|
+
}
|
|
102
|
+
/** Register `prop-{prop}-{value}` and `default-{prop}-{value}` utilities. */
|
|
103
|
+
for (const [cssPropKebabName, components] of componentsByCSSProp) {
|
|
104
|
+
const cssProps = [...components.values()].flatMap((component) => {
|
|
105
|
+
const cssProp = component.findCSSPropByKebabName(cssPropKebabName);
|
|
106
|
+
return cssProp ? [cssProp] : [];
|
|
107
|
+
});
|
|
108
|
+
const cssPropTypes = cssProps.map((cssProp) => cssProp.type);
|
|
109
|
+
const matchUtilitiesType = ['any'];
|
|
110
|
+
const matchUtilitiesValues = {
|
|
111
|
+
inherit: 'inherit',
|
|
112
|
+
};
|
|
113
|
+
cssProps.forEach((cssProp) => {
|
|
114
|
+
;
|
|
115
|
+
[...(cssProp.values ?? []), ...(cssProp.suggestedValues ?? [])].forEach((value) => {
|
|
116
|
+
matchUtilitiesValues[String(value)] = getCSSPropRawValue(cssProp, value);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
if (cssPropTypes.includes('number') && !cssPropTypes.includes('length')) {
|
|
120
|
+
const bareValueFunction = (value) => {
|
|
121
|
+
const numberValue = parseBareValueNumber(value.value);
|
|
122
|
+
if (numberValue === null)
|
|
123
|
+
return undefined;
|
|
124
|
+
return String(numberValue);
|
|
125
|
+
};
|
|
126
|
+
matchUtilitiesValues['__BARE_VALUE__'] = bareValueFunction;
|
|
127
|
+
}
|
|
128
|
+
if (cssPropTypes.includes('length')) {
|
|
129
|
+
for (const [spacingKey, spacingValue] of Object.entries(api.theme('spacing'))) {
|
|
130
|
+
matchUtilitiesValues[spacingKey] =
|
|
131
|
+
parseNumber(spacingKey, { strict: true }) !== null
|
|
132
|
+
? `--spacing(${spacingKey})`
|
|
133
|
+
: spacingValue;
|
|
134
|
+
}
|
|
135
|
+
const bareValueFunction = (value) => {
|
|
136
|
+
const numberValue = parseBareValueNumber(value.value);
|
|
137
|
+
if (numberValue === null)
|
|
138
|
+
return undefined;
|
|
139
|
+
return `--spacing(${numberValue})`;
|
|
140
|
+
};
|
|
141
|
+
matchUtilitiesValues['__BARE_VALUE__'] = bareValueFunction;
|
|
142
|
+
}
|
|
143
|
+
if (cssPropTypes.includes('color')) {
|
|
144
|
+
matchUtilitiesType.push('color'); // Allows using opacity modifiers
|
|
145
|
+
for (const colorKey in api.theme('colors')) {
|
|
146
|
+
matchUtilitiesValues[colorKey] = getCSSPropRawValue({ type: 'color', defaultValue: 'current' }, colorKey);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
api.matchUtilities(Object.fromEntries(['prop', 'default'].map((utilityType) => [
|
|
150
|
+
`${utilityType}-${cssPropKebabName}`,
|
|
151
|
+
(value) => ({
|
|
152
|
+
[`--gds-${utilityType}-${cssPropKebabName}`]: value,
|
|
153
|
+
}),
|
|
154
|
+
])), {
|
|
155
|
+
type: matchUtilitiesType,
|
|
156
|
+
values: matchUtilitiesValues,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Register `@prop-{prop}-{value}/{component}` and `@prop-not-{prop}-{value}/{component}` variants
|
|
161
|
+
* for props of type `values`, for components to use internally.
|
|
162
|
+
*/
|
|
163
|
+
for (const variant of ['@prop-not', '@prop']) {
|
|
164
|
+
api.matchVariant(variant, (cssPropKebabNameAndValue, { modifier: componentKebabName }) => {
|
|
165
|
+
/**
|
|
166
|
+
* If the modifier is explicitly `dummy`, consider the variant invalid by returning an empty
|
|
167
|
+
* selector list (no CSS will be generated for it).
|
|
168
|
+
*/
|
|
169
|
+
if (componentKebabName === 'dummy')
|
|
170
|
+
return [];
|
|
171
|
+
/**
|
|
172
|
+
* Default a missing modifier to `dummy` instead of considering the variant invalid so that
|
|
173
|
+
* it's suggested by Tailwind IntelliSense.
|
|
174
|
+
*/
|
|
175
|
+
const component = getRegisteredComponent(componentKebabName ?? 'dummy');
|
|
176
|
+
/**
|
|
177
|
+
* If no component is found (i.e. the modifier is not a valid component name), consider the
|
|
178
|
+
* variant invalid.
|
|
179
|
+
*/
|
|
180
|
+
if (!component)
|
|
181
|
+
return [];
|
|
182
|
+
try {
|
|
183
|
+
const { cssPropKebabName, value } = JSON.parse(cssPropKebabNameAndValue);
|
|
184
|
+
if (typeof cssPropKebabName !== 'string' ||
|
|
185
|
+
(typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean'))
|
|
186
|
+
return [];
|
|
187
|
+
const cssProp = component.findCSSPropByKebabName(cssPropKebabName);
|
|
188
|
+
/**
|
|
189
|
+
* Only consider the variant valid if the prop exists on the component and is of type
|
|
190
|
+
* `values`, and the value is valid for it (unless the component is `dummy`, which is used
|
|
191
|
+
* to list all variants in IntelliSense regardless of the component).
|
|
192
|
+
*/
|
|
193
|
+
if ((!cssProp || cssProp.type !== 'values' || !cssProp.values.includes(value)) &&
|
|
194
|
+
component.kebabName !== 'dummy') {
|
|
195
|
+
return [];
|
|
196
|
+
}
|
|
197
|
+
const rawValue = cssProp ? getCSSPropRawValue(cssProp, value) : String(value);
|
|
198
|
+
return [
|
|
199
|
+
/** Style query selector for modern browsers. */
|
|
200
|
+
`@container ${component.containerName} ${variant === '@prop-not' ? 'not' : ''} style(--gds-${component.kebabName}-${cssPropKebabName}: ${rawValue})`,
|
|
201
|
+
/**
|
|
202
|
+
* Fallback selector for browsers without style query support, which unfortunately
|
|
203
|
+
* cannot be queried, but happens to be the same browsers that don't support view
|
|
204
|
+
* transitions (except for Firefox which introduced support for view transitions in
|
|
205
|
+
* version 144 but not style queries). Note that we don't want the polyfill rules to be
|
|
206
|
+
* applied when style queries are supported to prevent bugs on the first render, where
|
|
207
|
+
* polyfill attributes are present even when the polyfill is not needed (see
|
|
208
|
+
* `useCSSPropsPolyfill` for an explanation why).
|
|
209
|
+
*/
|
|
210
|
+
`@supports (not (view-transition-name: none)) or (-moz-orient: inline) { &:where(.${component.className}${variant === '@prop-not' ? ':not' : ':is'}([data-gds-prop-polyfill-${cssPropKebabName}=${cssesc(rawValue, { isIdentifier: true })}]) *) }`,
|
|
211
|
+
];
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
/**
|
|
215
|
+
* If the value is invalid JSON (e.g. `@prop-[some-arbitrary-string]`), consider the
|
|
216
|
+
* variant invalid.
|
|
217
|
+
*/
|
|
218
|
+
return [];
|
|
219
|
+
}
|
|
220
|
+
}, {
|
|
221
|
+
values: Object.fromEntries([...componentsByCSSProp.entries()].flatMap(([cssPropKebabName, components]) => {
|
|
222
|
+
const cssPropValues = [...components.values()].flatMap((component) => component.findCSSPropByKebabName(cssPropKebabName)?.values ?? []);
|
|
223
|
+
return cssPropValues.map((value) => [
|
|
224
|
+
`${cssPropKebabName}-${value}`,
|
|
225
|
+
JSON.stringify({ cssPropKebabName, value }),
|
|
226
|
+
]);
|
|
227
|
+
})),
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=registerCSSProps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerCSSProps.js","sourceRoot":"","sources":["../../src/css-props/registerCSSProps.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAE3B,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtD,OAAO,EACL,sBAAsB,EACtB,uBAAuB,GAExB,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAG5D;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAc;IAC7C,MAAM,mBAAmB,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE;QACvF,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxD,MAAM,QAAQ,GACZ,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC;gBAC/B,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,GAAG,EAAwB,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAE,CAAA;YAC1F,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;QAC9C,CAAC;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC,EAAE,IAAI,GAAG,EAAqC,CAAC,CAAA;IAEhD,MAAM,iBAAiB,GAA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AAC;YAAC,MAAM,CAAC;gBACP;;;mBAGG;gBACH,OAAO,EAAE,CAAA;YACX,CAAC;QACH,CAAC,EACD;YACE,MAAM,EAAE,MAAM,CAAC,WAAW,CACxB,CAAC,GAAG,mBAAmB,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAAE,EAAE;gBAC5E,MAAM,aAAa,GAAG,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CACpD,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,EAAE,MAAM,IAAI,EAAE,CAChF,CAAA;gBACD,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;oBAClC,GAAG,gBAAgB,IAAI,KAAK,EAAE;oBAC9B,IAAI,CAAC,SAAS,CAAC,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;iBAC5C,CAAC,CAAA;YACJ,CAAC,CAAC,CACH;SACF,CACF,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { GDSColor } from '../design-tokens.generated.ts';
|
|
2
|
+
type CSSUnit = 'px' | 'em' | 'rem' | 'lh' | 'rlh' | '%' | 'vw' | 'vh' | 'vmin' | 'vmax';
|
|
3
|
+
type CSSLength = number | `${number}${CSSUnit}`;
|
|
4
|
+
export type CSSPropValue = string | number | boolean;
|
|
5
|
+
export type CSSPropString = string;
|
|
6
|
+
export type CSSPropNumber = number;
|
|
7
|
+
export type CSSPropLength = CSSLength;
|
|
8
|
+
export type CSSPropColor = GDSColor | `${GDSColor}/${number}`;
|
|
9
|
+
type Type = 'values' | 'string' | 'number' | 'length' | 'color';
|
|
10
|
+
type TypeToValue<T extends Type, V extends CSSPropValue = CSSPropValue> = T extends 'values' ? V : T extends 'string' ? CSSPropString : T extends 'number' ? CSSPropNumber : T extends 'length' ? CSSPropLength : CSSPropColor;
|
|
11
|
+
export type CSSPropDefinition<T extends Type = Type, V extends CSSPropValue[] = CSSPropValue[], D extends TypeToValue<T, V[number]> = TypeToValue<T, V[number]>> = T extends 'values' ? {
|
|
12
|
+
type: T;
|
|
13
|
+
values: V;
|
|
14
|
+
suggestedValues?: never;
|
|
15
|
+
defaultValue?: D & TypeToValue<T, V[number]>;
|
|
16
|
+
} : T extends 'number' ? {
|
|
17
|
+
type: T;
|
|
18
|
+
values?: never;
|
|
19
|
+
suggestedValues?: number[];
|
|
20
|
+
defaultValue?: D & TypeToValue<T>;
|
|
21
|
+
} : {
|
|
22
|
+
type: T;
|
|
23
|
+
values?: never;
|
|
24
|
+
suggestedValues?: never;
|
|
25
|
+
defaultValue?: D & TypeToValue<T>;
|
|
26
|
+
};
|
|
27
|
+
export type CSSPropType<P extends CSSPropDefinition> = P['values'] extends CSSPropValue[] ? TypeToValue<P['type'], P['values'][number]> : TypeToValue<P['type']>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/css-props/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AAE7D,KAAK,OAAO,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAA;AACvF,KAAK,SAAS,GAAG,MAAM,GAAG,GAAG,MAAM,GAAG,OAAO,EAAE,CAAA;AAE/C,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;AACpD,MAAM,MAAM,aAAa,GAAG,MAAM,CAAA;AAClC,MAAM,MAAM,aAAa,GAAG,MAAM,CAAA;AAClC,MAAM,MAAM,aAAa,GAAG,SAAS,CAAA;A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E,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;CAAE,CAAA;AAE7F,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,iBAAiB,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,YAAY,EAAE,GACrF,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,GAC3C,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/css-props/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/css-states/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,KAAK,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAA;AAC7F,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/css-states/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAqC,MAAM,aAAa,CAAA;AAC7F,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { PluginAPI } from '../types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Registers CSS States functionality in the Tailwind plugin.
|
|
4
|
+
*
|
|
5
|
+
* This system abstracts away CSS's native states in order to:
|
|
6
|
+
*
|
|
7
|
+
* - Allow overriding the state of components (e.g. `<Button className="state-active" />`).
|
|
8
|
+
* - Allow reading the state of components from their root element even when the native state is
|
|
9
|
+
* actually on a nested element (e.g. `group-has-checkbox-checked`), thanks to
|
|
10
|
+
* `variants/plugin.ts` overriding some of Tailwind's built-in variants.
|
|
11
|
+
* - Allow setting and reading custom states for DRY purposes (e.g. `active:state-[highlighted]` and
|
|
12
|
+
* `data-[highlighted]:state-[highlighted]` on a parent element and
|
|
13
|
+
* `@state-[highlighted]:bg-strong` on a child; also supports key-values like `state-[foo=bar]
|
|
14
|
+
* lg:state-[foo=baz]`).
|
|
15
|
+
*
|
|
16
|
+
* While this system is separate from the CSS Props one, it also leverages style queries and relies
|
|
17
|
+
* on the fact that component classes (e.g. `gds-button`) establish a container that can be queried.
|
|
18
|
+
* Furthermore, it uses some of the same techniques in the fallback implementation (querying by data
|
|
19
|
+
* attribute, `view-transition-name` to target browsers that don't support style queries, etc.),
|
|
20
|
+
* though the CSS props polyfill is not used. See `useCSSState` for more details.
|
|
21
|
+
*/
|
|
22
|
+
export declare function registerCSSStates(api: PluginAPI): void;
|
|
23
|
+
//# sourceMappingURL=registerCSSStates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerCSSStates.d.ts","sourceRoot":"","sources":["../../src/css-states/registerCSSStates.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAG5C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,SAAS,QA6G/C"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import cssesc from 'cssesc';
|
|
2
|
+
import { objectFromEntries } from 'ts-extras';
|
|
3
|
+
import { cssStates, cssStateVariables, getCSSStateVariable } from "./states.js";
|
|
4
|
+
/**
|
|
5
|
+
* Registers CSS States functionality in the Tailwind plugin.
|
|
6
|
+
*
|
|
7
|
+
* This system abstracts away CSS's native states in order to:
|
|
8
|
+
*
|
|
9
|
+
* - Allow overriding the state of components (e.g. `<Button className="state-active" />`).
|
|
10
|
+
* - Allow reading the state of components from their root element even when the native state is
|
|
11
|
+
* actually on a nested element (e.g. `group-has-checkbox-checked`), thanks to
|
|
12
|
+
* `variants/plugin.ts` overriding some of Tailwind's built-in variants.
|
|
13
|
+
* - Allow setting and reading custom states for DRY purposes (e.g. `active:state-[highlighted]` and
|
|
14
|
+
* `data-[highlighted]:state-[highlighted]` on a parent element and
|
|
15
|
+
* `@state-[highlighted]:bg-strong` on a child; also supports key-values like `state-[foo=bar]
|
|
16
|
+
* lg:state-[foo=baz]`).
|
|
17
|
+
*
|
|
18
|
+
* While this system is separate from the CSS Props one, it also leverages style queries and relies
|
|
19
|
+
* on the fact that component classes (e.g. `gds-button`) establish a container that can be queried.
|
|
20
|
+
* Furthermore, it uses some of the same techniques in the fallback implementation (querying by data
|
|
21
|
+
* attribute, `view-transition-name` to target browsers that don't support style queries, etc.),
|
|
22
|
+
* though the CSS props polyfill is not used. See `useCSSState` for more details.
|
|
23
|
+
*/
|
|
24
|
+
export function registerCSSStates(api) {
|
|
25
|
+
/**
|
|
26
|
+
* Register a couple custom properties for each state variable.
|
|
27
|
+
*
|
|
28
|
+
* - All of them are non-inherited to prevent leaking.
|
|
29
|
+
* - Normally, we would only need `--gds-exposed-*` and `--gds-state-*` (with no `initial-value` on
|
|
30
|
+
* `--gds-exposed-*`), but due to a limitation in the `style-observer` library
|
|
31
|
+
* (https://github.com/LeaVerou/style-observer/issues/133), we need to set an `initial-value` on
|
|
32
|
+
* any custom property we want to observe in JS. But we also need `--gds-state-*` to NOT have an
|
|
33
|
+
* initial value so that we can define a fallback when a state is not set at all (see
|
|
34
|
+
* `--gds-clickable-*`). So we register an additional `--gds-observed-*` property that is
|
|
35
|
+
* guaranteed to have a valid value and can be observed.
|
|
36
|
+
*/
|
|
37
|
+
for (const [variableName, { values, defaultValue }] of Object.entries(cssStateVariables)) {
|
|
38
|
+
api.addBase({
|
|
39
|
+
[`@property --gds-exposed-${variableName}`]: {
|
|
40
|
+
syntax: "'*'",
|
|
41
|
+
inherits: 'false',
|
|
42
|
+
'initial-value': '',
|
|
43
|
+
},
|
|
44
|
+
[`@property --gds-state-${variableName}`]: {
|
|
45
|
+
syntax: "'*'",
|
|
46
|
+
inherits: 'false',
|
|
47
|
+
},
|
|
48
|
+
[`@property --gds-observed-${variableName}`]: {
|
|
49
|
+
syntax: `'${[...new Set([...Object.values(values), defaultValue])].map((value) => String(value)).join(' | ')}'`,
|
|
50
|
+
inherits: 'false',
|
|
51
|
+
'initial-value': String(defaultValue),
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Register `expose-{state}` utilities for components to use internally to expose their current
|
|
57
|
+
* state if the root element doesn't already do so (e.g. by being a button with the expected
|
|
58
|
+
* attributes on it), as well as `state-{state}` utilities for consumers to trigger the
|
|
59
|
+
* hover/focus/etc. state of components that support it.
|
|
60
|
+
*/
|
|
61
|
+
api.matchUtilities({
|
|
62
|
+
expose: (state) => {
|
|
63
|
+
const stateVariable = getCSSStateVariable(state);
|
|
64
|
+
return {
|
|
65
|
+
[`--gds-exposed-${stateVariable.name}`]: stateVariable.value,
|
|
66
|
+
[`--gds-state-${stateVariable.name}`]: stateVariable.value,
|
|
67
|
+
[`--gds-observed-${stateVariable.name}`]: stateVariable.value,
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
state: (state) => {
|
|
71
|
+
const stateVariable = getCSSStateVariable(state);
|
|
72
|
+
return {
|
|
73
|
+
[`--gds-state-${stateVariable.name}`]: stateVariable.value,
|
|
74
|
+
[`--gds-observed-${stateVariable.name}`]: stateVariable.value,
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
}, { values: Object.fromEntries(cssStates.map((state) => [state, state])) });
|
|
78
|
+
/** Register `@state-*` and `@state-not-*` variants for components to use internally. */
|
|
79
|
+
for (const variant of ['@state-not', '@state']) {
|
|
80
|
+
api.matchVariant(variant, (state, { modifier }) => {
|
|
81
|
+
const containerName = modifier !== null ? `gds-${modifier}` : '';
|
|
82
|
+
const stateVariables = [getCSSStateVariable(state)];
|
|
83
|
+
// Make sure that `@state-hover` utilities are also applied on the active state
|
|
84
|
+
if (state === 'hover') {
|
|
85
|
+
stateVariables.push(getCSSStateVariable('active'));
|
|
86
|
+
}
|
|
87
|
+
const selectors = [
|
|
88
|
+
`@container ${containerName} ${variant === '@state-not' ? 'not' : ''} (${stateVariables
|
|
89
|
+
.flatMap((stateVariable) => {
|
|
90
|
+
const conditions = [
|
|
91
|
+
`style(--gds-state-${stateVariable.name}${stateVariable.value ? `: ${stateVariable.value}` : ''})`,
|
|
92
|
+
];
|
|
93
|
+
if (stateVariable.isDefault) {
|
|
94
|
+
conditions.push(`(not style(--gds-state-${stateVariable.name}))`);
|
|
95
|
+
}
|
|
96
|
+
return conditions;
|
|
97
|
+
})
|
|
98
|
+
.join(' or ')})`,
|
|
99
|
+
];
|
|
100
|
+
if (containerName) {
|
|
101
|
+
// Fallback selector for browsers without style query support; see `css-props/registerCSSProps.ts` for more details
|
|
102
|
+
selectors.push(`@supports (not (view-transition-name: none)) or (-moz-orient: inline) { &:where(.${containerName}${variant === '@state-not' ? ':not' : ':is'}(${stateVariables
|
|
103
|
+
.map((stateVariable) => `[data-gds-state-polyfill-${stateVariable.name}${stateVariable.value ? `=${cssesc(stateVariable.value, { isIdentifier: true })}` : ''}]`)
|
|
104
|
+
.join(', ')}) *) }`);
|
|
105
|
+
}
|
|
106
|
+
return selectors;
|
|
107
|
+
}, {
|
|
108
|
+
values: objectFromEntries(cssStates
|
|
109
|
+
.filter((state) => {
|
|
110
|
+
// Prevent creating `@state-not-not-*` variants
|
|
111
|
+
if (variant === '@state-not' && state.startsWith('not-'))
|
|
112
|
+
return false;
|
|
113
|
+
return true;
|
|
114
|
+
})
|
|
115
|
+
.map((state) => [state, state])),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=registerCSSStates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerCSSStates.js","sourceRoot":"","sources":["../../src/css-states/registerCSSStates.ts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AAO,IAAI,CAAA;YACb,CAAC,CAAC;iBACD,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAClC;SACF,CACF,CAAA;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export declare const cssStates: readonly ["open", "not-open", "current", "not-current", "checked", "indeterminate", "unchecked", "read-only", "blank", "not-blank", "idle", "hover", "focus", "not-focus", "active", "enabled", "disabled"];
|
|
2
|
+
export type CSSState = (typeof cssStates)[number];
|
|
3
|
+
export type CSSStateValue = string | boolean;
|
|
4
|
+
export declare const cssStateVariables: {
|
|
5
|
+
pointer: {
|
|
6
|
+
values: {
|
|
7
|
+
idle: "idle";
|
|
8
|
+
hover: "hover";
|
|
9
|
+
active: "active";
|
|
10
|
+
} & Record<"idle" | "hover" | "active", "idle" | "hover" | "active">;
|
|
11
|
+
defaultValue: "idle" | "hover" | "active";
|
|
12
|
+
};
|
|
13
|
+
focus: {
|
|
14
|
+
values: {
|
|
15
|
+
focus: true;
|
|
16
|
+
'not-focus': false;
|
|
17
|
+
} & Record<"focus" | "not-focus", boolean>;
|
|
18
|
+
defaultValue: boolean;
|
|
19
|
+
};
|
|
20
|
+
checked: {
|
|
21
|
+
values: {
|
|
22
|
+
checked: true;
|
|
23
|
+
indeterminate: "indeterminate";
|
|
24
|
+
unchecked: false;
|
|
25
|
+
} & Record<"checked" | "indeterminate" | "unchecked", boolean | "indeterminate">;
|
|
26
|
+
defaultValue: boolean | "indeterminate";
|
|
27
|
+
};
|
|
28
|
+
disabled: {
|
|
29
|
+
values: {
|
|
30
|
+
enabled: false;
|
|
31
|
+
disabled: true;
|
|
32
|
+
'read-only': "read-only";
|
|
33
|
+
} & Record<"read-only" | "enabled" | "disabled", boolean | "read-only">;
|
|
34
|
+
defaultValue: boolean | "read-only";
|
|
35
|
+
};
|
|
36
|
+
open: {
|
|
37
|
+
values: {
|
|
38
|
+
open: true;
|
|
39
|
+
'not-open': false;
|
|
40
|
+
} & Record<"open" | "not-open", boolean>;
|
|
41
|
+
defaultValue: boolean;
|
|
42
|
+
};
|
|
43
|
+
current: {
|
|
44
|
+
values: {
|
|
45
|
+
current: true;
|
|
46
|
+
'not-current': false;
|
|
47
|
+
} & Record<"current" | "not-current", boolean>;
|
|
48
|
+
defaultValue: boolean;
|
|
49
|
+
};
|
|
50
|
+
blank: {
|
|
51
|
+
values: {
|
|
52
|
+
blank: true;
|
|
53
|
+
'not-blank': false;
|
|
54
|
+
} & Record<"blank" | "not-blank", boolean>;
|
|
55
|
+
defaultValue: boolean;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export declare function getCSSStateVariable(state: string): {
|
|
59
|
+
name: string;
|
|
60
|
+
value: string;
|
|
61
|
+
isDefault: boolean;
|
|
62
|
+
};
|
|
63
|
+
export declare function getPointerStateSelector(state: 'idle' | 'hover' | 'active'): string;
|
|
64
|
+
export declare function getFocusStateSelector(visible: boolean, within: boolean): string;
|
|
65
|
+
export declare function getCheckedStateSelector(checked: boolean | 'indeterminate'): string;
|
|
66
|
+
export declare function getDisabledStateSelector(disabled: boolean | 'read-only'): string;
|
|
67
|
+
export declare function getOpenStateSelector(open: boolean): string;
|
|
68
|
+
export declare function getCurrentStateSelector(current: boolean): string;
|
|
69
|
+
export declare function getBlankStateSelector(blank: boolean): string;
|
|
70
|
+
export declare const cssStateSelectors: Record<CSSState, string>;
|
|
71
|
+
//# sourceMappingURL=states.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"states.d.ts","sourceRoot":"","sources":["../../src/css-states/states.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,6MAkBZ,CAAA;AAEV,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAA;AACjD,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,CAAA;AAU5C,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqD7B,CAAA;AAQD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM;;;;EAgBhD;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,UAEzE;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,UAEtE;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,UAEzE;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,OAAO,GAAG,WAAW,UAEvE;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,UAEjD;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,UAEvD;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,UAGnD;AAED,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAkBtD,CAAA"}
|