Skip to content

Commit 42b0406

Browse files
committed
reorg
1 parent 3b991ea commit 42b0406

File tree

3 files changed

+59
-52
lines changed

3 files changed

+59
-52
lines changed

packages/dev/s2-docs/pages/s2/Reference.mdx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ All Spectrum 2 color tokens are available across color properties (e.g., `backgr
2424

2525
Below are the rest of the `style` macro supported color properties.
2626

27-
<StyleMacroProperties properties={getPropertyDefinitions(['outlineColor', 'fill', 'stroke'])} />
27+
<StyleMacroProperties properties={getPropertyDefinitions('color')} />
2828

2929
## Spacing
3030

@@ -41,7 +41,7 @@ Spacing props like `margin` and `padding` accept values on a **4px grid**. These
4141

4242
Size props like `width` and `height` accept arbitrary pixel values. Values are converted to `rem` and multiplied by 1.25x on touch devices to increase hit targets.
4343

44-
<StyleMacroProperties properties={getPropertyDefinitions(['top', 'height'])} />
44+
<StyleMacroProperties properties={getPropertyDefinitions('dimensions')} />
4545

4646
## Text
4747

@@ -64,20 +64,21 @@ Type scales include: UI, Body, Heading, Title, Detail, and Code. Each scale has
6464
<S2Typography />
6565

6666

67-
<StyleMacroProperties properties={getPropertyDefinitions(['fontFamily', 'listStyleType', 'listStylePosition'])} />
67+
<StyleMacroProperties properties={getPropertyDefinitions('text')} />
6868

6969

7070
## Effects
7171

72-
<StyleMacroProperties properties={getPropertyDefinitions(['boxShadow', 'filter'])} />
72+
<StyleMacroProperties properties={getPropertyDefinitions('effects')} />
7373

7474
## Layout
7575

76-
<StyleMacroProperties properties={getPropertyDefinitions(['display'])} />
76+
<StyleMacroProperties properties={getPropertyDefinitions('layout')} />
7777

7878

7979
## Misc
8080

81+
<StyleMacroProperties properties={getPropertyDefinitions('misc')} />
8182

8283
## Shorthands
8384

packages/dev/s2-docs/src/styleProperties.ts

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
interface StyleMacroPropertyDefinition {
14-
// TODO: unneeded for now
15-
type: 'color' | 'mapped' | 'percentage' | 'sizing' | 'arbitrary',
16-
// Values tied to the property, usually manually defined for now
17-
values: string[],
18-
// Additional value types to append, usually used to add type links to generalize a type that
19-
// the property extends aka a css length percentage or a number that needs more explaination
20-
additionalTypes?: string[]
21-
}
22-
2313
// properties that extend from baseColors
2414
const baseColorProperties = new Set([
2515
'color', 'backgroundColor', 'borderColor', 'outlineColor', 'fill', 'stroke'
@@ -40,23 +30,21 @@ const sizingProperties = new Set([
4030
'flexBasis', 'containIntrinsicWidth', 'containIntrinsicHeight'
4131
]);
4232

43-
// manually defined
44-
// TODO: maybe spit these up into groups, and have getPropertyDefinitions grab via category name instead
45-
const propertyValues: {[key: string]: string[]} = {
46-
// Color
33+
34+
const colorPropertyValues: {[key: string]: string[]} = {
4735
// This should append baseColors in getPropertyDefinition
4836
outlineColor: ['focus-ring'],
4937
// This should append what seems to be a combination of semantic colors and background/global colors
5038
fill: ['none', 'currentColor'],
5139
stroke: ['none', 'currentColor'],
40+
};
5241

53-
54-
display: ['block', 'inline-block', 'inline', 'flex', 'inline-flex', 'grid', 'inline-grid', 'contents', 'list-item', 'none'],
42+
const dimensionsPropertyValues: {[key: string]: string[]} = {
5543
top: ['0', '2', '4', '8', '12', '16', '20', '24', '28', '32', '36', '40', '44', '48', '56', '64', '80', '96', '-2', '-4', '-8', '-12', '-16', '-20', '-24', '-28', '-32', '-36', '-40', '-44', '-48', '-56', '-64', '-80', '-96', 'auto', 'full'],
5644
height: ['auto', 'full', 'min', 'max', 'fit', 'screen'],
45+
};
5746

58-
59-
// text
47+
const textPropertyValues: {[key: string]: string[]} = {
6048
fontFamily: ['sans', 'serif', 'code'],
6149
// todo: skipped font-size, font-weight, line height though these will also just be manually defined here
6250
listStyleType: ['none', 'disc', 'decimal'],
@@ -65,7 +53,6 @@ const propertyValues: {[key: string]: string[]} = {
6553
textAlign: ['start', 'center', 'end', 'justify'],
6654
verticalAlign: ['baseline', 'top', 'middle', 'bottom', 'text-top', 'text-bottom', 'sub', 'super'],
6755
textDecoration: ['none' , 'underline' , 'overline' , 'line-through'],
68-
6956
textOverflow: ['ellipsis', 'clip'],
7057
lineClamp: ['number'],
7158
hyphens: ['none', 'manual', 'auto'],
@@ -74,52 +61,72 @@ const propertyValues: {[key: string]: string[]} = {
7461
wordBreak: ['normal', 'break-all', 'keep-all', 'break-word'],
7562
overflowWrap: ['normal', 'anywhere', 'break-word'],
7663
boxDecorationBreak: ['slice', 'clone'],
64+
};
7765

78-
// effects
66+
const effectsPropertyValues: {[key: string]: string[]} = {
7967
// TODO: should the below have a typelink explaining more details
8068
boxShadow: ['emphasized', 'elevated', 'dragged', 'none'],
8169
filter: ['emphasized', 'elevated', 'dragged', 'none'],
70+
};
71+
72+
const layoutPropertyValues: {[key: string]: string[]} = {
8273

74+
display: ['block', 'inline-block', 'inline', 'flex', 'inline-flex', 'grid', 'inline-grid', 'contents', 'list-item', 'none'],
8375
};
8476

85-
// TODO: will we need something specific for short hand?
86-
export function getPropertyDefinition(propertyName: string): StyleMacroPropertyDefinition {
87-
const values = propertyValues[propertyName] || [];
77+
const miscPropertyValues: {[key: string]: string[]} = {
78+
79+
};
80+
81+
const shorthandMapping: {[key: string]: string[]} = {
8882

83+
};
84+
85+
const conditionMapping: {[key: string]: string[]} = {
86+
87+
};
88+
89+
const properties: {[key: string]: {[key: string]: string[]}} = {
90+
color: colorPropertyValues,
91+
dimensions: dimensionsPropertyValues,
92+
text: textPropertyValues,
93+
effects: effectsPropertyValues,
94+
layout: layoutPropertyValues,
95+
misc: miscPropertyValues
96+
};
97+
98+
// TODO: will we need something specific for short hand?
99+
// TODO: see if there are any others that we will need to add additional shared types for
100+
export function getAdditionalTypes(propertyName: string): string[] {
89101
if (baseColorProperties.has(propertyName)) {
90-
return {
91-
type: 'color',
92-
values,
93-
additionalTypes: ['baseColors']
94-
}
102+
return ['baseColors']
95103
}
96104

97105
if (sizingProperties.has(propertyName)) {
98-
return {
99-
type: 'sizing',
100-
values,
101-
additionalTypes: ['number', 'LengthPercentage']
102-
};
106+
return ['number', 'LengthPercentage']
103107
}
104108

105109
if (percentageProperties.has(propertyName)) {
106-
return {
107-
type: 'percentage',
108-
values,
109-
additionalTypes: ['LengthPercentage']
110-
};
110+
return ['LengthPercentage']
111111
}
112112

113-
return {
114-
type: 'mapped',
115-
values
116-
};
113+
return [];
114+
}
115+
116+
interface StyleMacroPropertyDefinition {
117+
values: string[],
118+
additionalTypes?: string[]
117119
}
118120

119-
export function getPropertyDefinitions(propertyNames: string[]): {[key: string]: StyleMacroPropertyDefinition} {
120-
const result: {[key: string]: StyleMacroPropertyDefinition} = {};
121-
for (const name of propertyNames) {
122-
result[name] = getPropertyDefinition(name);
121+
export function getPropertyDefinitions(propertyCategory: string): {[key: string]: StyleMacroPropertyDefinition} {
122+
let result: {[key: string]: StyleMacroPropertyDefinition} = {};
123+
let propertiesMapping = properties[propertyCategory] || {};
124+
125+
for (let [name, values] of Object.entries(propertiesMapping)) {
126+
result[name] = {
127+
values,
128+
additionalTypes: getAdditionalTypes(name)
129+
}
123130
}
124131
return result;
125132
}

packages/dev/s2-docs/src/types.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,6 @@ function TemplateLiteral({elements}: TTemplate) {
696696
}
697697

698698
interface StyleMacroPropertyDefinition {
699-
type: 'color' | 'mapped' | 'percentage' | 'sizing' | 'arbitrary',
700699
values: string[],
701700
additionalTypes?: string[]
702701
}

0 commit comments

Comments
 (0)