diff --git a/change/@fluentui-react-components-cfddd7d4-0c30-425c-88bd-5fe3a4f09453.json b/change/@fluentui-react-components-cfddd7d4-0c30-425c-88bd-5fe3a4f09453.json new file mode 100644 index 00000000000000..5efe6ce95e280c --- /dev/null +++ b/change/@fluentui-react-components-cfddd7d4-0c30-425c-88bd-5fe3a4f09453.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Export TypographyStyle type", + "packageName": "@fluentui/react-components", + "email": "miroslav.stastny@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/change/@fluentui-react-theme-84c82566-de8b-43d7-9e67-49ae3cbae176.json b/change/@fluentui-react-theme-84c82566-de8b-43d7-9e67-49ae3cbae176.json new file mode 100644 index 00000000000000..cd3a279c53cdef --- /dev/null +++ b/change/@fluentui-react-theme-84c82566-de8b-43d7-9e67-49ae3cbae176.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Export TypographyStyle type", + "packageName": "@fluentui/react-theme", + "email": "miroslav.stastny@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/packages/react-components/react-components/etc/react-components.api.md b/packages/react-components/react-components/etc/react-components.api.md index b8240487b38d5c..90efa6567b4424 100644 --- a/packages/react-components/react-components/etc/react-components.api.md +++ b/packages/react-components/react-components/etc/react-components.api.md @@ -359,6 +359,7 @@ import { TooltipProps } from '@fluentui/react-tooltip'; import { TooltipSlots } from '@fluentui/react-tooltip'; import { TooltipState } from '@fluentui/react-tooltip'; import { TooltipTriggerProps } from '@fluentui/react-tooltip'; +import { TypographyStyle } from '@fluentui/react-theme'; import { TypographyStyles } from '@fluentui/react-theme'; import { typographyStyles } from '@fluentui/react-theme'; import { UninitializedMenuListState } from '@fluentui/react-menu'; @@ -1172,6 +1173,8 @@ export { TooltipState } export { TooltipTriggerProps } +export { TypographyStyle } + export { TypographyStyles } export { typographyStyles } diff --git a/packages/react-components/react-components/src/index.ts b/packages/react-components/react-components/src/index.ts index b28dd8bb151289..5bc58312d3146c 100644 --- a/packages/react-components/react-components/src/index.ts +++ b/packages/react-components/react-components/src/index.ts @@ -77,6 +77,7 @@ export type { DurationTokens, CurveTokens, Theme, + TypographyStyle, TypographyStyles, } from '@fluentui/react-theme'; export { useThemeClassName } from '@fluentui/react-shared-contexts'; diff --git a/packages/react-components/react-theme/etc/react-theme.api.md b/packages/react-components/react-theme/etc/react-theme.api.md index e7b7210a805d66..5305cc58552dd1 100644 --- a/packages/react-components/react-theme/etc/react-theme.api.md +++ b/packages/react-components/react-theme/etc/react-theme.api.md @@ -473,6 +473,14 @@ export function themeToTokensObject(theme: TTheme): Record // @public (undocumented) export const tokens: Record; +// @public (undocumented) +export type TypographyStyle = { + fontFamily: string; + fontSize: string; + fontWeight: string; + lineHeight: string; +}; + // @public (undocumented) export type TypographyStyles = { body1: TypographyStyle; diff --git a/packages/react-components/react-theme/src/index.ts b/packages/react-components/react-theme/src/index.ts index a12bf4667a7a34..c04d94f90cc19b 100644 --- a/packages/react-components/react-theme/src/index.ts +++ b/packages/react-components/react-theme/src/index.ts @@ -74,5 +74,6 @@ export type { ColorTokens, PartialTheme, Theme, + TypographyStyle, TypographyStyles, } from './types'; diff --git a/packages/react-components/react-theme/src/themes/ThemeTypography.stories.tsx b/packages/react-components/react-theme/src/themes/ThemeTypography.stories.tsx index b34731e24140e9..8ddd12a019e617 100644 --- a/packages/react-components/react-theme/src/themes/ThemeTypography.stories.tsx +++ b/packages/react-components/react-theme/src/themes/ThemeTypography.stories.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; -import { teamsLightTheme } from '../index'; -import type { FontFamilyTokens, FontSizeTokens, LineHeightTokens, FontWeightTokens } from '../index'; +import { teamsLightTheme, typographyStyles } from '../index'; +import type { FontFamilyTokens, FontSizeTokens, LineHeightTokens, FontWeightTokens, TypographyStyle } from '../index'; export default { title: 'Theme', @@ -71,3 +71,49 @@ export const FontWeight = () => ( )} ); + +export const TypographyStyles = () => { + // var(--tokenName) => tokenName + function formatTypographyStyleValue(typographyStyleValue: TypographyStyle) { + return ( +
+ {Object.values(typographyStyleValue).map(value => ( +
{value.replace(/var\(--(.+)\)/, '$1')}
+ ))} +
+ ); + } + + // caption1Strong => Caption 1 Strong + function formatTypographyStyleName(typographyStyleName: string) { + return typographyStyleName.replace(/([A-Z\d])/g, ' $1').replace(/^(.)/, firstChar => firstChar.toUpperCase()); + } + + return ( +
+
+ Typography style is represented by a set of tokens instead of an individual token. +
+
+ {(Object.keys(typographyStyles) as (keyof typeof typographyStyles)[]).map(typographyStyleName => [ +
{typographyStyleName}
, +
+ {formatTypographyStyleValue(typographyStyles[typographyStyleName])} +
, +
+ Hello, I am {formatTypographyStyleName(typographyStyleName)} +
, + ])} +
+
+ ); +}; diff --git a/packages/react-components/react-theme/src/types.ts b/packages/react-components/react-theme/src/types.ts index 8a4580036ed33c..d65f7927a5cd25 100644 --- a/packages/react-components/react-theme/src/types.ts +++ b/packages/react-components/react-theme/src/types.ts @@ -875,7 +875,7 @@ export type TextAlignments = { justify: TextAlignment; }; -type TypographyStyle = { +export type TypographyStyle = { fontFamily: string; fontSize: string; fontWeight: string;