1010 * governing permissions and limitations under the License.
1111 */
1212
13- // Properties that extend from baseColors
14- const baseColorProperties = new Set ( [
15- 'color' , 'backgroundColor' , 'borderColor' , 'outlineColor' , 'fill' , 'stroke'
16- ] ) ;
17-
1813// Properties that use PercentageProperty (accept LengthPercentage in addition to mapped values)
1914const percentageProperties = new Set ( [
2015 'top' , 'left' , 'bottom' , 'right' ,
@@ -67,7 +62,7 @@ const fontSize = [
6762] ;
6863
6964const colorPropertyValues : { [ key : string ] : string [ ] } = {
70- color : [ 'accent' , 'neutral' , 'neutral-subdued' , 'negative' , 'disabled' , 'heading' , 'title' , 'body' , 'detail' , 'code' , 'auto' ] ,
65+ color : [ 'accent' , 'neutral' , 'neutral-subdued' , 'negative' , 'disabled' , 'heading' , 'title' , 'body' , 'detail' , 'code' , 'auto' , 'baseColors' ] ,
7166 backgroundColor : [
7267 'accent' , 'accent-subtle' , 'neutral' , 'neutral-subdued' , 'neutral-subtle' ,
7368 'negative' , 'negative-subtle' , 'informative' , 'informative-subtle' ,
@@ -81,18 +76,18 @@ const colorPropertyValues: {[key: string]: string[]} = {
8176 'magenta' , 'magenta-subtle' , 'pink' , 'pink-subtle' ,
8277 'turquoise' , 'turquoise-subtle' , 'cinnamon' , 'cinnamon-subtle' ,
8378 'brown' , 'brown-subtle' , 'silver' , 'silver-subtle' ,
84- 'disabled' , 'base' , 'layer-1' , 'layer-2' , 'pasteboard' , 'elevated'
79+ 'disabled' , 'base' , 'layer-1' , 'layer-2' , 'pasteboard' , 'elevated' , 'baseColors'
8580 ] ,
86- borderColor : [ 'negative' , 'disabled' ] ,
87- outlineColor : [ 'focus-ring' ] ,
81+ borderColor : [ 'negative' , 'disabled' , 'baseColors' ] ,
82+ outlineColor : [ 'focus-ring' , 'baseColors' ] ,
8883 fill : [
8984 'none' , 'currentColor' ,
9085 'accent' , 'neutral' , 'negative' , 'informative' , 'positive' , 'notice' ,
9186 'gray' , 'red' , 'orange' , 'yellow' , 'chartreuse' , 'celery' , 'green' ,
9287 'seafoam' , 'cyan' , 'blue' , 'indigo' , 'purple' , 'fuchsia' , 'magenta' ,
93- 'pink' , 'turquoise' , 'cinnamon' , 'brown' , 'silver'
88+ 'pink' , 'turquoise' , 'cinnamon' , 'brown' , 'silver' , 'baseColors'
9489 ] ,
95- stroke : [ 'none' , 'currentColor' ]
90+ stroke : [ 'none' , 'currentColor' , 'baseColors' ]
9691} ;
9792
9893const dimensionsPropertyValues : { [ key : string ] : string [ ] } = {
@@ -170,7 +165,6 @@ const textPropertyValues: {[key: string]: string[]} = {
170165 boxDecorationBreak : [ 'slice' , 'clone' ]
171166} ;
172167
173-
174168const effectsPropertyValues : { [ key : string ] : string [ ] } = {
175169 boxShadow : [ 'emphasized' , 'elevated' , 'dragged' , 'none' ] ,
176170 filter : [ 'emphasized' , 'elevated' , 'dragged' , 'none' ] ,
@@ -370,13 +364,10 @@ const properties: {[key: string]: {[key: string]: string[]}} = {
370364// TODO: will we need something specific for short hand?
371365// TODO: see if there are any others that we will need to add additional shared types for
372366// this is less additional types and more that we want to represent the below as a type link
367+ // special custom types that should be appended to the property but need special handling (render a type popover)
373368export function getAdditionalTypes ( propertyName : string ) : string [ ] {
374369 let types : string [ ] = [ ] ;
375370
376- if ( baseColorProperties . has ( propertyName ) ) {
377- types . push ( 'baseColors' ) ;
378- }
379-
380371 if ( baseSpacingProperties . has ( propertyName ) ) {
381372 types . push ( 'baseSpacing' ) ;
382373 }
@@ -401,57 +392,82 @@ export const spacingTypeValues = {
401392 negativeSpacing : negativeBaseSpacingValues
402393} ;
403394
395+ // opted NOT to link to Fonts from 'ui', 'code', etc since the visual example
396+ // is so close to the area in the table where those are rendered
397+ const relativeLinks : { [ key : string ] : string } = {
398+ 'text-to-control' : '#dimensions' ,
399+ 'text-to-visual' : '#dimensions' ,
400+ 'edge-to-text' : '#dimensions' ,
401+ 'pill' : '#dimensions' ,
402+ 'baseColors' : '#colors'
403+ }
404+
404405const mdnTypeLinks : { [ key : string ] : string } = {
405406 'string' : 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String' ,
406- 'number' : 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number' ,
407+ 'number' : 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number'
407408} ;
408409
409- const mdnPropertyLinks : { [ key : string ] : { [ value : string ] : string } } = {
410+ const mdnPropertyLinks : { [ key : string ] : { [ value : string ] : { href : string , isRelative ?: boolean } } } = {
410411 'flexShrink' : {
411- 'number' : 'https://developer.mozilla.org/en-US/docs/Web/CSS/flex-shrink'
412+ 'number' : {
413+ href : 'https://developer.mozilla.org/en-US/docs/Web/CSS/flex-shrink' ,
414+ }
412415 } ,
413416 'flexGrow' : {
414- 'number' : 'https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow'
417+ 'number' : {
418+ href : 'https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow'
419+ }
415420 } ,
416421 'gridColumnStart' : {
417- 'string' : 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column-start'
422+ 'string' : {
423+ href : 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column-start'
424+ }
418425 } ,
419426 'gridColumnEnd' : {
420- 'string' : 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column-end'
427+ 'string' : {
428+ href : 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-column-end'
429+ }
421430 } ,
422431 'gridRowStart' : {
423- 'string' : 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-row-start'
432+ 'string' : {
433+ href : 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-row-start'
434+ }
424435 } ,
425436 'gridRowEnd' : {
426- 'string' : 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-row-end'
437+ 'string' : {
438+ href : 'https://developer.mozilla.org/en-US/docs/Web/CSS/grid-row-end'
439+ }
427440 }
428441} ;
429442
430443interface StyleMacroPropertyDefinition {
431444 values : string [ ] ,
432445 additionalTypes ?: string [ ] ,
433- links ?: { [ value : string ] : string }
446+ links ?: { [ value : string ] : { href : string , isRelative ?: boolean } }
434447}
435448
436449export function getPropertyDefinitions ( propertyCategory : string ) : { [ key : string ] : StyleMacroPropertyDefinition } {
437450 let result : { [ key : string ] : StyleMacroPropertyDefinition } = { } ;
438451 let propertiesMapping = properties [ propertyCategory ] || { } ;
439452
440453 for ( let [ name , values ] of Object . entries ( propertiesMapping ) ) {
441- let links : { [ value : string ] : string } = { } ;
454+ let links : { [ value : string ] : { href : string , isRelative ?: boolean } } = { } ;
442455
443456 if ( mdnPropertyLinks [ name ] ) {
444457 links = { ...mdnPropertyLinks [ name ] } ;
445458 values = [ Object . keys ( links ) [ 0 ] ] ;
446459 } else {
447460 // see if the property has any common types that should link to MDN instead
448461 for ( let value of values ) {
462+ // make sure not to overwrite number in sizing properties and pill in other sections aka effects
463+ if ( ( value === 'number' && sizingProperties . has ( name ) ) || ( value === 'pill' && propertyCategory !== 'dimensions' ) ) {
464+ continue ;
465+ }
466+
449467 if ( mdnTypeLinks [ value ] ) {
450- // make sure not to overwrite number in sizing properties
451- if ( value === 'number' && sizingProperties . has ( name ) ) {
452- continue ;
453- }
454- links [ value ] = mdnTypeLinks [ value ] ;
468+ links [ value ] = { href : mdnTypeLinks [ value ] } ;
469+ } else if ( relativeLinks [ value ] ) {
470+ links [ value ] = { href : relativeLinks [ value ] , isRelative : true } ;
455471 }
456472 }
457473 }
0 commit comments