Skip to content

Commit 5d2b172

Browse files
committed
add descriptions to table and get rid of unessasary isRelative
1 parent 83262ef commit 5d2b172

File tree

3 files changed

+79
-77
lines changed

3 files changed

+79
-77
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ Size props like `width` and `height` accept arbitrary pixel values. Values are c
3737

3838
## Text
3939

40-
// TODO: edit copy
41-
4240
Spectrum 2 typography can be applied via the `font` [shorthand](#shorthand), which sets `fontFamily`, `fontSize`, `fontWeight`, `lineHeight`, and `color`. You can override any of these individually.
4341

4442
```tsx

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

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ export const spacingTypeValues = {
392392
negativeSpacing: negativeBaseSpacingValues
393393
};
394394

395+
// a mapping of value to relative links that should be replaced in place
395396
// opted NOT to link to Fonts from 'ui', 'code', etc since the visual example
396397
// is so close to the area in the table where those are rendered
397398
const relativeLinks: {[key: string]: string} = {
@@ -402,48 +403,46 @@ const relativeLinks: {[key: string]: string} = {
402403
'baseColors': '#colors'
403404
}
404405

406+
// a mapping of value to mdn links that should be replaced in place
405407
const mdnTypeLinks: {[key: string]: string} = {
406408
'string': 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String',
407409
'number': 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number'
408410
};
409411

410-
const mdnPropertyLinks: {[key: string]: {[value: string]: {href: string, isRelative?: boolean}}} = {
412+
// a mapping of value to links that should be replaced in place with the provided string
413+
const mdnPropertyLinks: {[key: string]: {[value: string]: string}} = {
411414
'flexShrink': {
412-
'number': {
413-
href: 'https://developer.mozilla.org/en-US/docs/Web/CSS/flex-shrink',
414-
}
415+
'number': 'https://developer.mozilla.org/en-US/docs/Web/CSS/flex-shrink'
415416
},
416417
'flexGrow': {
417-
'number': {
418-
href: 'https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow'
419-
}
418+
'number': 'https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow'
420419
},
421420
'gridColumnStart': {
422-
'string': {
423-
href: 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column-start'
424-
}
421+
'string': 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column-start'
425422
},
426423
'gridColumnEnd': {
427-
'string': {
428-
href: 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column-end'
429-
}
424+
'string': 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column-end'
430425
},
431426
'gridRowStart': {
432-
'string': {
433-
href: 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-row-start'
434-
}
427+
'string': 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-row-start'
435428
},
436429
'gridRowEnd': {
437-
'string': {
438-
href: 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-row-end'
439-
}
430+
'string': 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-row-end'
440431
}
441432
};
442433

434+
const propertyDescriptions: {[key: string]: string} = {
435+
'rotate': 'Accepts a number (treated as degrees) or a string with units (deg, rad, grad, turn).',
436+
'scaleX': 'Accepts a number or percentage string.',
437+
'scaleY': 'Accepts a number or percentage string.',
438+
'aspectRatio': 'Also accepts a ratio in the format number/number (e.g., 16/9, 4/3).'
439+
};
440+
443441
interface StyleMacroPropertyDefinition {
444442
values: string[],
445443
additionalTypes?: string[],
446-
links?: {[value: string]: {href: string, isRelative?: boolean}}
444+
links?: {[value: string]: {href: string, isRelative?: boolean}},
445+
description?: string
447446
}
448447

449448
export function getPropertyDefinitions(propertyCategory: string): {[key: string]: StyleMacroPropertyDefinition} {
@@ -454,8 +453,9 @@ export function getPropertyDefinitions(propertyCategory: string): {[key: string]
454453
let links: {[value: string]: {href: string, isRelative?: boolean}} = {};
455454

456455
if (mdnPropertyLinks[name]) {
457-
links = {...mdnPropertyLinks[name]};
458-
values = [Object.keys(links)[0]];
456+
let [key, value] = Object.entries(mdnPropertyLinks[name])[0];
457+
links[key] = {href: value};
458+
values = [key];
459459
} else {
460460
// see if the property has any common types that should link to MDN instead
461461
for (let value of values) {
@@ -475,7 +475,8 @@ export function getPropertyDefinitions(propertyCategory: string): {[key: string]
475475
result[name] = {
476476
values,
477477
additionalTypes: getAdditionalTypes(name),
478-
links: Object.keys(links).length > 0 ? links : undefined
478+
links: Object.keys(links).length > 0 ? links : undefined,
479+
description: propertyDescriptions[name]
479480
};
480481
}
481482
return result;

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

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -754,14 +754,14 @@ function StyleMacroTypePopover({typeName, description, body}: StyleMacroTypePopo
754754
interface StyleMacroPropertyDefinition {
755755
values: string[],
756756
additionalTypes?: string[],
757-
links?: {[value: string]: {href: string, isRelative?: boolean}}
757+
links?: {[value: string]: {href: string, isRelative?: boolean}},
758+
description?: string
758759
}
759760

760761
interface StyleMacroPropertiesProps {
761762
properties: {[propertyName: string]: StyleMacroPropertyDefinition}
762763
}
763764

764-
// TODO: fix the width of the columns so that they are consistent
765765
export function StyleMacroProperties({properties}: StyleMacroPropertiesProps) {
766766
let propertyNames = Object.keys(properties);
767767

@@ -780,62 +780,65 @@ export function StyleMacroProperties({properties}: StyleMacroPropertiesProps) {
780780
let links = propDef.links || {};
781781

782782
return (
783-
<TableRow key={index}>
784-
<TableCell role="rowheader">
785-
<code className={codeStyle}>
786-
<span className={codeStyles.attribute}>{propertyName}</span>
787-
</code>
788-
</TableCell>
789-
<TableCell>
790-
<code className={codeStyle}>
791-
{values.map((value, i) => (
792-
<React.Fragment key={i}>
793-
{i > 0 && <Punctuation>{' | '}</Punctuation>}
794-
{links[value] ? (
795-
<ColorLink
796-
href={links[value].href}
797-
type="variable"
798-
rel={links[value].isRelative ? undefined : "noreferrer"}
799-
target={links[value].isRelative ? undefined : "_blank"}>
800-
{value}
801-
</ColorLink>
802-
) : (
803-
<span className={codeStyles.string}>'{value}'</span>
804-
)}
805-
</React.Fragment>
806-
))}
807-
{propDef.additionalTypes && propDef.additionalTypes.map((typeName, i) => {
808-
let typeLink = styleMacroTypeLinks[typeName];
809-
return (
810-
<React.Fragment key={`type-${i}`}>
811-
{(values.length > 0 || i > 0) && <Punctuation>{' | '}</Punctuation>}
812-
{typeLink ? (
813-
// only if the type link has a description and/or body do we want to render the type popover
814-
// this is to make things like baseColor
815-
typeLink.link && !typeLink.description && !typeLink.body ? (
816-
<ColorLink href={typeLink.link} type="variable">{typeName}</ColorLink>
817-
) : (
818-
<StyleMacroTypePopover
819-
typeName={typeName}
820-
description={typeLink.description}
821-
body={typeLink.body} />
822-
)
823-
) : undefined}
783+
<React.Fragment key={index}>
784+
<TableRow>
785+
<TableCell role="rowheader" hideBorder={!!propDef.description}>
786+
<code className={codeStyle}>
787+
<span className={codeStyles.attribute}>{propertyName}</span>
788+
</code>
789+
</TableCell>
790+
<TableCell hideBorder={!!propDef.description}>
791+
<code className={codeStyle}>
792+
{values.map((value, i) => (
793+
<React.Fragment key={i}>
794+
{i > 0 && <Punctuation>{' | '}</Punctuation>}
795+
{links[value] ? (
796+
<ColorLink
797+
href={links[value].href}
798+
type="variable"
799+
rel={links[value].isRelative ? undefined : "noreferrer"}
800+
target={links[value].isRelative ? undefined : "_blank"}>
801+
{value}
802+
</ColorLink>
803+
) : (
804+
<span className={codeStyles.string}>'{value}'</span>
805+
)}
824806
</React.Fragment>
825-
);
826-
})}
827-
</code>
828-
</TableCell>
829-
</TableRow>
807+
))}
808+
{propDef.additionalTypes && propDef.additionalTypes.map((typeName, i) => {
809+
let typeLink = styleMacroTypeLinks[typeName];
810+
return (
811+
<React.Fragment key={`type-${i}`}>
812+
{(values.length > 0 || i > 0) && <Punctuation>{' | '}</Punctuation>}
813+
{typeLink ? (
814+
// only if the type link has a description and/or body do we want to render the type popover
815+
// this is to make things like baseColor
816+
typeLink.link && !typeLink.description && !typeLink.body ? (
817+
<ColorLink href={typeLink.link} type="variable">{typeName}</ColorLink>
818+
) : (
819+
<StyleMacroTypePopover
820+
typeName={typeName}
821+
description={typeLink.description}
822+
body={typeLink.body} />
823+
)
824+
) : undefined}
825+
</React.Fragment>
826+
);
827+
})}
828+
</code>
829+
</TableCell>
830+
</TableRow>
831+
{propDef.description && (
832+
<TableRow>
833+
<TableCell colSpan={2}>{propDef.description}</TableCell>
834+
</TableRow>
835+
)}
836+
</React.Fragment>
830837
);
831838
})}
832839
</TableBody>
833840
</Table>
834841
);
835842
}
836843

837-
// same for spacing, perhaps do the type that contains the same explaination, and remove the text blob
838-
// TODO: add to the table a description col span 2 to describe what things like aspectRatio and such accept (aka This takes a). this exists in the Prop table so look there
839-
840844
// TODO: For the Shorthands, have a column for Name, value (what values it accepts), and mapping where mapping is what properties it maps to
841-
//

0 commit comments

Comments
 (0)