Skip to content

Commit a31a5b6

Browse files
authored
feat(react-cap-theme): introduce style hook to specifically opt into border radius updates (#662)
Co-authored-by: David Zukowski <6439050+davezuko@users.noreply.github.com>
1 parent a77fb89 commit a31a5b6

26 files changed

Lines changed: 1430 additions & 47 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Introduce CAP_STYLE_HOOKS_ROUNDED_CORNERS",
4+
"packageName": "@fluentui-contrib/react-cap-theme",
5+
"email": "6439050+davezuko@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Constrain the docs reading column to a comfortable width and center it.
3+
* The shared docs CSS sets `.sbdocs-content` to max-width: 1200px; this
4+
* package-scoped override narrows it and centers the column. The extra class in
5+
* the selector raises specificity so it wins regardless of stylesheet order.
6+
*/
7+
#storybook-docs .sbdocs.sbdocs-content {
8+
max-width: 800px;
9+
margin-left: auto;
10+
margin-right: auto;
11+
}

packages/react-cap-theme/.storybook/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import rootConfig from '../../../.storybook/main';
55
const config: StorybookConfig = {
66
...rootConfig,
77
addons: [...(rootConfig.addons ?? []), 'storybook-addon-pseudo-states'],
8-
stories: ['../stories/**/index.stories.@(js|jsx|ts|tsx|mdx)'],
8+
stories: [
9+
'../stories/**/index.stories.@(js|jsx|ts|tsx)',
10+
'../stories/**/index.mdx',
11+
],
912
};
1013

1114
export default config;

packages/react-cap-theme/.storybook/preview.tsx

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
import * as React from 'react';
22
import rootPreview from '../../../.storybook/preview';
3-
import {
4-
FluentProvider,
5-
Theme,
6-
webLightTheme,
7-
} from '@fluentui/react-components';
8-
import { CAP_STYLE_HOOKS } from '../src/index';
3+
import { FluentProvider, webLightTheme } from '@fluentui/react-components';
4+
import { CAP_STYLE_HOOKS, CAP_THEME_TOKENS } from '../src/index';
95
import type { JSXElement } from '@fluentui/react-utilities';
106

117
import type { Preview, StoryFn } from '@storybook/react';
12-
import { CAPTokens } from '../src/components/tokens/types';
138

14-
const capTheme: Record<keyof Theme & keyof CAPTokens, string> = {
15-
...webLightTheme,
16-
borderRadius2XLarge: '12px',
17-
borderRadius3XLarge: '16px',
18-
borderRadius4XLarge: '24px',
19-
colorNeutralStroke4: '#ebebeb',
20-
colorNeutralStroke4Hover: '#e0e0e0',
21-
colorNeutralStroke4Pressed: '#d6d6d6',
22-
colorNeutralStroke4Selected: '#ebebeb',
23-
colorNeutralForeground5: '#616161',
24-
colorNeutralForeground5Hover: '#242424',
25-
colorNeutralForeground5Pressed: '#242424',
26-
};
9+
// Imported after `rootPreview` so this package's docs overrides win.
10+
import './docs.css';
11+
12+
const capTheme = { ...webLightTheme, ...CAP_THEME_TOKENS };
2713

2814
const preview: Preview = {
2915
...rootPreview,
@@ -37,6 +23,26 @@ const preview: Preview = {
3723
</FluentProvider>
3824
),
3925
],
26+
parameters: {
27+
...rootPreview.parameters,
28+
options: {
29+
storySort: {
30+
order: [
31+
'Packages',
32+
[
33+
'react-cap-theme',
34+
[
35+
'Getting Started',
36+
'Design Language',
37+
['Overview', 'Rounded Corners'],
38+
'Components',
39+
'*',
40+
],
41+
],
42+
],
43+
},
44+
},
45+
},
4046
tags: ['autodocs'],
4147
};
4248

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { capTokens } from './tokens';
1+
export { capTokens, CAP_THEME_TOKENS } from './tokens';
Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
11
import { CAPTokens } from './types';
22

3-
export const capTokens: Record<keyof CAPTokens, string> = {
4-
borderRadius2XLarge: 'var(--borderRadius2XLarge)',
5-
borderRadius3XLarge: 'var(--borderRadius3XLarge)',
6-
borderRadius4XLarge: 'var(--borderRadius4XLarge)',
7-
colorNeutralStroke4: 'var(--colorNeutralStroke4)',
8-
colorNeutralStroke4Hover: 'var(--colorNeutralStroke4Hover)',
9-
colorNeutralStroke4Pressed: 'var(--colorNeutralStroke4Pressed)',
10-
colorNeutralStroke4Selected: 'var(--colorNeutralStroke4Selected)',
11-
colorNeutralForeground5: 'var(--colorNeutralForeground5)',
12-
colorNeutralForeground5Hover: 'var(--colorNeutralForeground5Hover)',
13-
colorNeutralForeground5Pressed: 'var(--colorNeutralForeground5Pressed)',
3+
/**
4+
* Default values for the CAP-specific design tokens (the ones Fluent v9 doesn't
5+
* ship yet). These defaults are baked into the CAP style hooks (see `capTokens`)
6+
* as CSS-variable fallbacks, so consumers don't have to set them by default.
7+
*
8+
* Override a value by defining the matching theme token on your `FluentProvider`
9+
* theme — that emits the CSS variable, which takes precedence over the fallback.
10+
* To override several at once, spread these onto your base theme:
11+
*
12+
* ```tsx
13+
* const capTheme = { ...webLightTheme, ...CAP_THEME_TOKENS };
14+
* ```
15+
*/
16+
export const CAP_THEME_TOKENS: Record<keyof CAPTokens, string> = {
17+
borderRadius2XLarge: '12px',
18+
borderRadius3XLarge: '16px',
19+
borderRadius4XLarge: '24px',
20+
colorNeutralStroke4: '#ebebeb',
21+
colorNeutralStroke4Hover: '#e0e0e0',
22+
colorNeutralStroke4Pressed: '#d6d6d6',
23+
colorNeutralStroke4Selected: '#ebebeb',
24+
colorNeutralForeground5: '#616161',
25+
colorNeutralForeground5Hover: '#242424',
26+
colorNeutralForeground5Pressed: '#242424',
1427
};
28+
29+
/**
30+
* The CAP tokens as CSS-variable references for use inside style hooks. Each one
31+
* carries its {@link CAP_THEME_TOKENS} default as a fallback, so the hooks work
32+
* even when the consumer hasn't defined the token on their theme; defining it
33+
* (e.g. via `CAP_THEME_TOKENS`) overrides the fallback.
34+
*/
35+
export const capTokens: Record<keyof CAPTokens, string> = Object.fromEntries(
36+
(Object.keys(CAP_THEME_TOKENS) as (keyof CAPTokens)[]).map((key) => [
37+
key,
38+
`var(--${key}, ${CAP_THEME_TOKENS[key]})`,
39+
])
40+
) as Record<keyof CAPTokens, string>;

0 commit comments

Comments
 (0)