Skip to content

update rating to use semantic tokens #34672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "Feat: Add semantic tokens to Rating",
"packageName": "@fluentui/react-rating",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@fluentui/react-theme": "^9.1.24",
"@fluentui/react-tabster": "^9.24.6",
"@fluentui/react-utilities": "^9.19.0",
"@fluentui/semantic-tokens": "0.0.0-alpha.1",
"@griffel/react": "^1.5.22",
"@swc/helpers": "^0.5.1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { makeResetStyles, makeStyles, mergeClasses } from '@griffel/react';
import type { SlotClassNames } from '@fluentui/react-utilities';
import type { RatingDisplaySlots, RatingDisplayState } from './RatingDisplay.types';
import { tokens, typographyStyles } from '@fluentui/react-theme';
import * as semanticTokens from '@fluentui/semantic-tokens';

export const ratingDisplayClassNames: SlotClassNames<RatingDisplaySlots> = {
root: 'fui-RatingDisplay',
Expand All @@ -20,24 +20,27 @@ const useRootClassName = makeResetStyles({
});

const useLabelClassName = makeResetStyles({
color: tokens.colorNeutralForeground1,
marginLeft: tokens.spacingHorizontalXS,
...typographyStyles.caption1,
color: semanticTokens.foregroundCtrlNeutralPrimaryRest,
marginLeft: semanticTokens.gapInsideCtrlSmToLabel,
fontFamily: semanticTokens.textStyleDefaultRegularFontFamily,
fontSize: semanticTokens.textRampSmItemBodyFontSize,
fontWeight: semanticTokens.textStyleDefaultRegularWeight,
lineHeight: semanticTokens.textRampSmItemBodyLineHeight,
});

const useLabelStyles = makeStyles({
large: {
fontSize: tokens.fontSizeBase300,
lineHeight: tokens.lineHeightBase300,
marginLeft: tokens.spacingHorizontalSNudge,
fontSize: semanticTokens.textRampItemBodyFontSize,
lineHeight: semanticTokens.textRampItemBodyLineHeight,
marginLeft: semanticTokens.gapInsideCtrlToLabel,
},
extraLarge: {
fontSize: tokens.fontSizeBase400,
lineHeight: tokens.lineHeightBase400,
marginLeft: tokens.spacingHorizontalS,
fontSize: semanticTokens.textRampLgItemBodyFontSize,
lineHeight: semanticTokens.textRampLgItemBodyLineHeight,
marginLeft: semanticTokens.gapInsideCtrlLgToLabel,
},
strong: {
fontWeight: tokens.fontWeightSemibold,
fontWeight: semanticTokens.textStyleDefaultHeaderWeight,
},
divider: {
'::before': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { SlotClassNames } from '@fluentui/react-utilities';
import { tokens } from '@fluentui/react-theme';
import { createFocusOutlineStyle } from '@fluentui/react-tabster';
import type { RatingItemSlots, RatingItemState } from './RatingItem.types';
import * as semanticTokens from '@fluentui/semantic-tokens';

export const ratingItemClassNames: SlotClassNames<RatingItemSlots> = {
root: 'fui-RatingItem',
Expand Down Expand Up @@ -70,7 +71,7 @@ const useInputStyles = makeStyles({
const useIndicatorBaseClassName = makeResetStyles({
display: 'flex',
overflow: 'hidden',
color: tokens.colorNeutralForeground1,
color: semanticTokens.ctrlRatingIconForegroundFilled,
fill: 'currentColor',
pointerEvents: 'none',
position: 'absolute',
Expand Down Expand Up @@ -98,8 +99,8 @@ const useIndicatorStyles = makeStyles({
color: tokens.colorPaletteMarigoldBorderActive,
},
filled: {
color: tokens.colorNeutralBackground6,
stroke: tokens.colorTransparentStroke,
color: semanticTokens.ctrlRatingIconForegroundEmpty,
stroke: semanticTokens.strokeLayer,
'@media (forced-colors: active)': {
color: 'Canvas',
stroke: 'CanvasText',
Expand Down
10 changes: 5 additions & 5 deletions packages/semantic-tokens/etc/semantic-tokens.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2237,13 +2237,13 @@ export const ctrlProgressSmHeightFilled = "var(--smtc-ctrl-progress-sm-height-fi
export const ctrlProgressSmHeightFilledRaw = "--smtc-ctrl-progress-sm-height-filled";

// @public (undocumented)
export const ctrlRatingIconForegroundEmpty = "var(--smtc-ctrl-rating-icon-foreground-empty, var(--smtc-ctrl-progress-background-empty))";
export const ctrlRatingIconForegroundEmpty = "var(--smtc-ctrl-rating-icon-foreground-empty, var(--smtc-ctrl-progress-background-empty, var(--colorNeutralBackground6)))";

// @public (undocumented)
export const ctrlRatingIconForegroundEmptyRaw = "--smtc-ctrl-rating-icon-foreground-empty";

// @public (undocumented)
export const ctrlRatingIconForegroundFilled = "var(--smtc-ctrl-rating-icon-foreground-filled, var(--smtc-background-ctrl-brand-rest))";
export const ctrlRatingIconForegroundFilled = "var(--smtc-ctrl-rating-icon-foreground-filled, var(--smtc-background-ctrl-brand-rest, var(--colorNeutralForeground1)))";

// @public (undocumented)
export const ctrlRatingIconForegroundFilledRaw = "--smtc-ctrl-rating-icon-foreground-filled";
Expand Down Expand Up @@ -3209,7 +3209,7 @@ export const gapInsideCtrlLgDefault = "var(--smtc-gap-inside-ctrl-lg-default, va
export const gapInsideCtrlLgDefaultRaw = "--smtc-gap-inside-ctrl-lg-default";

// @public (undocumented)
export const gapInsideCtrlLgToLabel = "var(--smtc-gap-inside-ctrl-lg-to-label)";
export const gapInsideCtrlLgToLabel = "var(--smtc-gap-inside-ctrl-lg-to-label, var(--spacingHorizontalS))";

// @public (undocumented)
export const gapInsideCtrlLgToLabelRaw = "--smtc-gap-inside-ctrl-lg-to-label";
Expand All @@ -3227,7 +3227,7 @@ export const gapInsideCtrlSmDefault = "var(--smtc-gap-inside-ctrl-sm-default, va
export const gapInsideCtrlSmDefaultRaw = "--smtc-gap-inside-ctrl-sm-default";

// @public (undocumented)
export const gapInsideCtrlSmToLabel = "var(--smtc-gap-inside-ctrl-sm-to-label)";
export const gapInsideCtrlSmToLabel = "var(--smtc-gap-inside-ctrl-sm-to-label, var(--spacingHorizontalXS))";

// @public (undocumented)
export const gapInsideCtrlSmToLabelRaw = "--smtc-gap-inside-ctrl-sm-to-label";
Expand All @@ -3239,7 +3239,7 @@ export const gapInsideCtrlSmToSecondaryIcon = "var(--smtc-gap-inside-ctrl-sm-to-
export const gapInsideCtrlSmToSecondaryIconRaw = "--smtc-gap-inside-ctrl-sm-to-secondary-icon";

// @public (undocumented)
export const gapInsideCtrlToLabel = "var(--smtc-gap-inside-ctrl-to-label)";
export const gapInsideCtrlToLabel = "var(--smtc-gap-inside-ctrl-to-label, var(--spacingHorizontalSNudge))";

// @public (undocumented)
export const gapInsideCtrlToLabelRaw = "--smtc-gap-inside-ctrl-to-label";
Expand Down
5 changes: 3 additions & 2 deletions packages/semantic-tokens/src/components/rating/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// THIS FILE IS GENERATED AS PART OF THE BUILD PROCESS. DO NOT MANUALLY MODIFY THIS FILE
import { iconThemeCtrlDefaultRestRaw, backgroundCtrlBrandRestRaw, sizeCtrlIconRaw } from '../../control/variables';
import { colorNeutralForeground1, colorNeutralBackground6 } from '../../legacy/tokens';
import { ctrlProgressBackgroundEmptyRaw } from '../progress/variables';
import {
ctrlRatingIconThemeRaw,
Expand All @@ -11,6 +12,6 @@ import {

export const ctrlRatingIconTheme = `var(${ctrlRatingIconThemeRaw}, var(${iconThemeCtrlDefaultRestRaw}))`;
export const ctrlRatingIconGap = `var(${ctrlRatingIconGapRaw})`;
export const ctrlRatingIconForegroundFilled = `var(${ctrlRatingIconForegroundFilledRaw}, var(${backgroundCtrlBrandRestRaw}))`;
export const ctrlRatingIconForegroundEmpty = `var(${ctrlRatingIconForegroundEmptyRaw}, var(${ctrlProgressBackgroundEmptyRaw}))`;
export const ctrlRatingIconForegroundFilled = `var(${ctrlRatingIconForegroundFilledRaw}, var(${backgroundCtrlBrandRestRaw}, ${colorNeutralForeground1}))`;
export const ctrlRatingIconForegroundEmpty = `var(${ctrlRatingIconForegroundEmptyRaw}, var(${ctrlProgressBackgroundEmptyRaw}, ${colorNeutralBackground6}))`;
export const ctrlRatingIconSize = `var(${ctrlRatingIconSizeRaw}, var(${sizeCtrlIconRaw}))`;
6 changes: 3 additions & 3 deletions packages/semantic-tokens/src/control/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ export const gapInsideCtrlSmToSecondaryIcon = `var(${gapInsideCtrlSmToSecondaryI
export const gapInsideCtrlLgDefault = `var(${gapInsideCtrlLgDefaultRaw}, ${spacingHorizontalSNudge})`;
export const gapInsideCtrlLgToSecondaryIcon = `var(${gapInsideCtrlLgToSecondaryIconRaw})`;
export const gapInsideCtrlToSecondaryIcon = `var(${gapInsideCtrlToSecondaryIconRaw})`;
export const gapInsideCtrlToLabel = `var(${gapInsideCtrlToLabelRaw})`;
export const gapInsideCtrlSmToLabel = `var(${gapInsideCtrlSmToLabelRaw})`;
export const gapInsideCtrlLgToLabel = `var(${gapInsideCtrlLgToLabelRaw})`;
export const gapInsideCtrlToLabel = `var(${gapInsideCtrlToLabelRaw}, ${spacingHorizontalSNudge})`;
export const gapInsideCtrlSmToLabel = `var(${gapInsideCtrlSmToLabelRaw}, ${spacingHorizontalXS})`;
export const gapInsideCtrlLgToLabel = `var(${gapInsideCtrlLgToLabelRaw}, ${spacingHorizontalS})`;
export const cornerCircular = `var(${cornerCircularRaw}, ${borderRadiusCircular})`;
export const strokeWidthDefault = `var(${strokeWidthDefaultRaw}, ${strokeWidthThin})`;
export const backgroundSmoke = `var(${backgroundSmokeRaw})`;
Expand Down
5 changes: 5 additions & 0 deletions packages/semantic-tokens/src/fluentOverrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export const fluentOverrides: FluentOverrides = {
ctrlProgressHeightFilled: { rawValue: '100%' },
ctrlProgressLgHeightEmpty: { rawValue: '4px' },
ctrlProgressLgHeightFilled: { rawValue: '100%' },
ctrlRatingIconForegroundEmpty: { f2Token: 'colorNeutralBackground6' }, // should be #D9DDE3 per design
ctrlRatingIconForegroundFilled: { f2Token: 'colorNeutralForeground1' }, // should be #24282F per design
foregroundContentBrandPrimary: { f2Token: 'colorBrandForeground1' },
foregroundContentNeutralPrimary: { f2Token: 'colorNeutralForeground1' },
foregroundContentNeutralSecondary: { f2Token: 'colorNeutralForeground2' },
Expand Down Expand Up @@ -123,7 +125,10 @@ export const fluentOverrides: FluentOverrides = {
foregroundCtrlOnTransparentRest: { f2Token: 'colorNeutralForeground2' },
gapInsideCtrlDefault: { f2Token: 'spacingHorizontalS' },
gapInsideCtrlLgDefault: { f2Token: 'spacingHorizontalSNudge' },
gapInsideCtrlLgToLabel: { f2Token: 'spacingHorizontalS' },
gapInsideCtrlSmDefault: { f2Token: 'spacingHorizontalXS' },
gapInsideCtrlSmToLabel: { f2Token: 'spacingHorizontalXS' }, // Rating uses 8px, or spacingHorizontalS, for all gaps between icons and label in design
gapInsideCtrlToLabel: { f2Token: 'spacingHorizontalSNudge' }, // Rating uses 8px, or spacingHorizontalS, for all gaps between icons and label in design
nullColor: { f2Token: 'colorTransparentBackground' },
paddingCtrlHorizontalDefault: { f2Token: 'spacingHorizontalM' },
paddingCtrlHorizontalIconOnly: { rawValue: '5px' },
Expand Down
8 changes: 4 additions & 4 deletions packages/semantic-tokens/src/legacy/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ export const colorNeutralForeground2Pressed = 'var(--colorNeutralForeground2Pres
*/
export const colorNeutralForeground2 = 'var(--colorNeutralForeground2)';
/**
* CSS custom property value for the {@link @fluentui/tokens#colorBrandForeground1 | `colorBrandForeground1`} design token.
* CSS custom property value for the {@link @fluentui/tokens#colorNeutralForeground1 | `colorNeutralForeground1`} design token.
* @public
*/
export const colorBrandForeground1 = 'var(--colorBrandForeground1)';
export const colorNeutralForeground1 = 'var(--colorNeutralForeground1)';
/**
* CSS custom property value for the {@link @fluentui/tokens#colorNeutralForeground1 | `colorNeutralForeground1`} design token.
* CSS custom property value for the {@link @fluentui/tokens#colorBrandForeground1 | `colorBrandForeground1`} design token.
* @public
*/
export const colorNeutralForeground1 = 'var(--colorNeutralForeground1)';
export const colorBrandForeground1 = 'var(--colorBrandForeground1)';
/**
* CSS custom property value for the {@link @fluentui/tokens#colorNeutralForeground2BrandHover | `colorNeutralForeground2BrandHover`} design token.
* @public
Expand Down
Loading