@fluentui/react-storybook-addon 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -2
- package/dist/index.d.ts +100 -0
- package/lib/components/DirectionSwitch.js +26 -0
- package/lib/components/DirectionSwitch.js.map +1 -0
- package/lib/components/ReactStrictMode.js +22 -0
- package/lib/components/ReactStrictMode.js.map +1 -0
- package/lib/components/ThemePicker.js +60 -0
- package/lib/components/ThemePicker.js.map +1 -0
- package/lib/constants.js +4 -0
- package/lib/constants.js.map +1 -0
- package/lib/decorators/withAriaLive.js +18 -0
- package/lib/decorators/withAriaLive.js.map +1 -0
- package/lib/decorators/withFluentProvider.js +48 -0
- package/lib/decorators/withFluentProvider.js.map +1 -0
- package/lib/decorators/withReactStrictMode.js +16 -0
- package/lib/decorators/withReactStrictMode.js.map +1 -0
- package/lib/docs/CopyAsMarkdownButton.js +177 -0
- package/lib/docs/CopyAsMarkdownButton.js.map +1 -0
- package/lib/docs/DirSwitch.js +51 -0
- package/lib/docs/DirSwitch.js.map +1 -0
- package/lib/docs/FluentCanvas.js +21 -0
- package/lib/docs/FluentCanvas.js.map +1 -0
- package/lib/docs/FluentDocsContainer.js +24 -0
- package/lib/docs/FluentDocsContainer.js.map +1 -0
- package/lib/docs/FluentDocsPage.js +308 -0
- package/lib/docs/FluentDocsPage.js.map +1 -0
- package/lib/docs/FluentStory.js +18 -0
- package/lib/docs/FluentStory.js.map +1 -0
- package/lib/docs/ThemePicker.js +61 -0
- package/lib/docs/ThemePicker.js.map +1 -0
- package/lib/docs/Toc.js +130 -0
- package/lib/docs/Toc.js.map +1 -0
- package/lib/docs/index.js +4 -0
- package/lib/docs/index.js.map +1 -0
- package/lib/docs/utils.js +74 -0
- package/lib/docs/utils.js.map +1 -0
- package/lib/hooks.js +16 -0
- package/lib/hooks.js.map +1 -0
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -0
- package/lib/preset/manager.js +25 -0
- package/lib/preset/manager.js.map +1 -0
- package/lib/preset/preview.js +26 -0
- package/lib/preset/preview.js.map +1 -0
- package/lib/theme.js +31 -0
- package/lib/theme.js.map +1 -0
- package/lib/utils/isDecoratorDisabled.js +6 -0
- package/lib/utils/isDecoratorDisabled.js.map +1 -0
- package/lib-commonjs/components/DirectionSwitch.js +37 -0
- package/lib-commonjs/components/DirectionSwitch.js.map +1 -0
- package/lib-commonjs/components/ReactStrictMode.js +33 -0
- package/lib-commonjs/components/ReactStrictMode.js.map +1 -0
- package/lib-commonjs/components/ThemePicker.js +71 -0
- package/lib-commonjs/components/ThemePicker.js.map +1 -0
- package/lib-commonjs/constants.js +28 -0
- package/lib-commonjs/constants.js.map +1 -0
- package/lib-commonjs/decorators/withAriaLive.js +29 -0
- package/lib-commonjs/decorators/withAriaLive.js.map +1 -0
- package/lib-commonjs/decorators/withFluentProvider.js +59 -0
- package/lib-commonjs/decorators/withFluentProvider.js.map +1 -0
- package/lib-commonjs/decorators/withReactStrictMode.js +27 -0
- package/lib-commonjs/decorators/withReactStrictMode.js.map +1 -0
- package/lib-commonjs/docs/CopyAsMarkdownButton.js +185 -0
- package/lib-commonjs/docs/CopyAsMarkdownButton.js.map +1 -0
- package/lib-commonjs/docs/DirSwitch.js +60 -0
- package/lib-commonjs/docs/DirSwitch.js.map +1 -0
- package/lib-commonjs/docs/FluentCanvas.js +29 -0
- package/lib-commonjs/docs/FluentCanvas.js.map +1 -0
- package/lib-commonjs/docs/FluentDocsContainer.js +33 -0
- package/lib-commonjs/docs/FluentDocsContainer.js.map +1 -0
- package/lib-commonjs/docs/FluentDocsPage.js +319 -0
- package/lib-commonjs/docs/FluentDocsPage.js.map +1 -0
- package/lib-commonjs/docs/FluentStory.js +26 -0
- package/lib-commonjs/docs/FluentStory.js.map +1 -0
- package/lib-commonjs/docs/ThemePicker.js +70 -0
- package/lib-commonjs/docs/ThemePicker.js.map +1 -0
- package/lib-commonjs/docs/Toc.js +149 -0
- package/lib-commonjs/docs/Toc.js.map +1 -0
- package/lib-commonjs/docs/index.js +28 -0
- package/lib-commonjs/docs/index.js.map +1 -0
- package/lib-commonjs/docs/utils.js +88 -0
- package/lib-commonjs/docs/utils.js.map +1 -0
- package/lib-commonjs/hooks.js +37 -0
- package/lib-commonjs/hooks.js.map +1 -0
- package/lib-commonjs/index.js +34 -0
- package/lib-commonjs/index.js.map +1 -0
- package/lib-commonjs/preset/manager.js +29 -0
- package/lib-commonjs/preset/manager.js.map +1 -0
- package/lib-commonjs/preset/preview.js +47 -0
- package/lib-commonjs/preset/preview.js.map +1 -0
- package/lib-commonjs/theme.js +49 -0
- package/lib-commonjs/theme.js.map +1 -0
- package/lib-commonjs/utils/isDecoratorDisabled.js +16 -0
- package/lib-commonjs/utils/isDecoratorDisabled.js.map +1 -0
- package/package.json +20 -27
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "FluentDocsPage", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return FluentDocsPage;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
|
+
const _blocks = require("@storybook/addon-docs/blocks");
|
|
14
|
+
const _reacttheme = require("@fluentui/react-theme");
|
|
15
|
+
const _reactlink = require("@fluentui/react-link");
|
|
16
|
+
const _reacttext = require("@fluentui/react-text");
|
|
17
|
+
const _react1 = require("@griffel/react");
|
|
18
|
+
const _reacticons = require("@fluentui/react-icons");
|
|
19
|
+
const _constants = require("../constants");
|
|
20
|
+
const _theme = require("../theme");
|
|
21
|
+
const _utils = require("./utils");
|
|
22
|
+
const _DirSwitch = require("./DirSwitch");
|
|
23
|
+
const _ThemePicker = require("./ThemePicker");
|
|
24
|
+
const _Toc = require("./Toc");
|
|
25
|
+
const _CopyAsMarkdownButton = require("./CopyAsMarkdownButton");
|
|
26
|
+
const useStyles = (0, _react1.makeStyles)({
|
|
27
|
+
divider: {
|
|
28
|
+
height: '1px',
|
|
29
|
+
backgroundColor: '#e1dfdd',
|
|
30
|
+
border: '0px none',
|
|
31
|
+
margin: '48px 0px'
|
|
32
|
+
},
|
|
33
|
+
wrapper: {
|
|
34
|
+
display: 'flex',
|
|
35
|
+
gap: '16px'
|
|
36
|
+
},
|
|
37
|
+
toc: {
|
|
38
|
+
flexBasis: '200px',
|
|
39
|
+
flexShrink: 0,
|
|
40
|
+
[`@media screen and (max-width: 1000px)`]: {
|
|
41
|
+
display: 'none'
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
container: {
|
|
45
|
+
// without a width, this div grows wider than its parent
|
|
46
|
+
width: '200px',
|
|
47
|
+
flexGrow: 1
|
|
48
|
+
},
|
|
49
|
+
globalTogglesContainer: {
|
|
50
|
+
columnGap: _reacttheme.tokens.spacingHorizontalXXXL,
|
|
51
|
+
display: 'flex'
|
|
52
|
+
},
|
|
53
|
+
description: {
|
|
54
|
+
display: 'grid',
|
|
55
|
+
gridTemplateColumns: '1fr min-content'
|
|
56
|
+
},
|
|
57
|
+
additionalInfoWrapper: {
|
|
58
|
+
display: 'flex',
|
|
59
|
+
flexDirection: 'column',
|
|
60
|
+
gap: _reacttheme.tokens.spacingVerticalM
|
|
61
|
+
},
|
|
62
|
+
additionalInfo: {
|
|
63
|
+
display: 'flex',
|
|
64
|
+
flexDirection: 'column',
|
|
65
|
+
gap: _reacttheme.tokens.spacingVerticalM,
|
|
66
|
+
border: `1px solid ${_reacttheme.tokens.colorNeutralStroke1}`,
|
|
67
|
+
borderRadius: _reacttheme.tokens.borderRadiusMedium,
|
|
68
|
+
padding: _reacttheme.tokens.spacingHorizontalM,
|
|
69
|
+
margin: `0 ${_reacttheme.tokens.spacingHorizontalM}`
|
|
70
|
+
},
|
|
71
|
+
additionalInfoIcon: {
|
|
72
|
+
alignSelf: 'center',
|
|
73
|
+
color: _reacttheme.tokens.colorBrandForeground1,
|
|
74
|
+
fontSize: '24px',
|
|
75
|
+
marginRight: _reacttheme.tokens.spacingHorizontalM
|
|
76
|
+
},
|
|
77
|
+
additionalInfoMessage: {
|
|
78
|
+
display: 'flex',
|
|
79
|
+
flexDirection: 'row',
|
|
80
|
+
alignItems: 'center',
|
|
81
|
+
gap: _reacttheme.tokens.spacingVerticalXS
|
|
82
|
+
},
|
|
83
|
+
infoIcon: {
|
|
84
|
+
display: 'flex',
|
|
85
|
+
flexDirection: 'column',
|
|
86
|
+
gap: _reacttheme.tokens.spacingVerticalXS,
|
|
87
|
+
flex: 1
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const useVideoClasses = (0, _react1.makeStyles)({
|
|
91
|
+
container: {
|
|
92
|
+
display: 'flex',
|
|
93
|
+
flexDirection: 'column',
|
|
94
|
+
gap: _reacttheme.tokens.spacingHorizontalMNudge
|
|
95
|
+
},
|
|
96
|
+
preview: {
|
|
97
|
+
borderRadius: _reacttheme.tokens.borderRadiusSmall,
|
|
98
|
+
display: 'flex',
|
|
99
|
+
flexDirection: 'column',
|
|
100
|
+
gap: _reacttheme.tokens.spacingHorizontalM,
|
|
101
|
+
padding: _reacttheme.tokens.spacingHorizontalM,
|
|
102
|
+
backgroundColor: _reacttheme.tokens.colorNeutralBackground2,
|
|
103
|
+
':hover': {
|
|
104
|
+
backgroundColor: _reacttheme.tokens.colorNeutralBackground2Hover
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
image: {
|
|
108
|
+
width: '200px'
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
const VideoPreviews = (props)=>{
|
|
112
|
+
const { videos } = props;
|
|
113
|
+
const classes = useVideoClasses();
|
|
114
|
+
return /*#__PURE__*/ _react.createElement("div", {
|
|
115
|
+
className: classes.container
|
|
116
|
+
}, videos.map((video)=>/*#__PURE__*/ _react.createElement(_reactlink.Link, {
|
|
117
|
+
className: classes.preview,
|
|
118
|
+
href: video.href,
|
|
119
|
+
target: "_blank",
|
|
120
|
+
key: video.href
|
|
121
|
+
}, /*#__PURE__*/ _react.createElement("img", {
|
|
122
|
+
alt: `Video: ${video.preview}`,
|
|
123
|
+
src: video.preview,
|
|
124
|
+
className: classes.image
|
|
125
|
+
}), /*#__PURE__*/ _react.createElement(_reacttext.Text, null, video.title))));
|
|
126
|
+
};
|
|
127
|
+
const getNativeElementsList = (elements)=>{
|
|
128
|
+
const elementsArr = elements === null || elements === void 0 ? void 0 : elements.map((el, idx)=>[
|
|
129
|
+
/*#__PURE__*/ _react.createElement("code", {
|
|
130
|
+
key: idx
|
|
131
|
+
}, `<${el}>`),
|
|
132
|
+
idx !== elements.length - 1 ? ', ' : ' '
|
|
133
|
+
]);
|
|
134
|
+
return /*#__PURE__*/ _react.createElement(_react.Fragment, null, elementsArr, elementsArr.length > 1 ? 'elements' : 'element');
|
|
135
|
+
};
|
|
136
|
+
const slotRegex = /as\?:\s*"([^"]+)"/;
|
|
137
|
+
/**
|
|
138
|
+
* NOTE: this function mutates original story argTypes including all story subcomponents if they are present
|
|
139
|
+
*/ function withSlotEnhancer(story, options) {
|
|
140
|
+
var _story_argTypes_as_type, _story_argTypes_as;
|
|
141
|
+
const hasArgAsProp = options.nativePropsApi ? ((_story_argTypes_as = story.argTypes.as) === null || _story_argTypes_as === void 0 ? void 0 : (_story_argTypes_as_type = _story_argTypes_as.type) === null || _story_argTypes_as_type === void 0 ? void 0 : _story_argTypes_as_type.name) === 'enum' : false;
|
|
142
|
+
const argAsProp = hasArgAsProp ? story.argTypes.as.type.value : null;
|
|
143
|
+
let hasArgAsSlot = false;
|
|
144
|
+
const transformArgTypeNameWithSlotShorthand = (typeName)=>{
|
|
145
|
+
const match = typeName.match(slotRegex);
|
|
146
|
+
if (match) {
|
|
147
|
+
hasArgAsSlot = true;
|
|
148
|
+
return `Slot<\"${match[1]}\">`;
|
|
149
|
+
}
|
|
150
|
+
if (typeName.includes('WithSlotShorthandValue')) {
|
|
151
|
+
hasArgAsSlot = true;
|
|
152
|
+
return `Slot`;
|
|
153
|
+
}
|
|
154
|
+
return typeName;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Transform the arg types with slot shorthand (mutates the arg types object reference)
|
|
158
|
+
* This is necessary to ensure that the arg types are correctly displayed in the docs page
|
|
159
|
+
*/ const transformArgTypesWithSlotShorthand = (argTypes)=>{
|
|
160
|
+
Object.values(argTypes).forEach((argType)=>{
|
|
161
|
+
var _argType_table_type, _argType_table, _argType_type;
|
|
162
|
+
// Transform the type summary if it exists
|
|
163
|
+
if (argType === null || argType === void 0 ? void 0 : (_argType_table = argType.table) === null || _argType_table === void 0 ? void 0 : (_argType_table_type = _argType_table.type) === null || _argType_table_type === void 0 ? void 0 : _argType_table_type.summary) {
|
|
164
|
+
argType.table.type.summary = transformArgTypeNameWithSlotShorthand(argType.table.type.summary);
|
|
165
|
+
}
|
|
166
|
+
// Transform the type name if it exists
|
|
167
|
+
if (argType === null || argType === void 0 ? void 0 : (_argType_type = argType.type) === null || _argType_type === void 0 ? void 0 : _argType_type.name) {
|
|
168
|
+
argType.type.name = transformArgTypeNameWithSlotShorthand(argType.type.name);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
const transformComponentDocGenProps = (component)=>{
|
|
173
|
+
var _component___docgenInfo;
|
|
174
|
+
const docGenProps = component === null || component === void 0 ? void 0 : (_component___docgenInfo = component.__docgenInfo) === null || _component___docgenInfo === void 0 ? void 0 : _component___docgenInfo.props;
|
|
175
|
+
if (docGenProps) {
|
|
176
|
+
transformArgTypesWithSlotShorthand(docGenProps);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const component = story.moduleExport;
|
|
180
|
+
if (options.slotsApi) {
|
|
181
|
+
// Transform the arg types with slot shorthand (mutates the arg types object reference)
|
|
182
|
+
transformArgTypesWithSlotShorthand(story.argTypes);
|
|
183
|
+
// Transform the component doc gen props with slot shorthand (mutates the component doc gen props object reference)
|
|
184
|
+
transformComponentDocGenProps(component);
|
|
185
|
+
// Transform the subcomponents doc gen props with slot shorthand
|
|
186
|
+
// (mutates the subcomponents doc gen props object reference)
|
|
187
|
+
if (story.subcomponents) {
|
|
188
|
+
Object.values(story.subcomponents).forEach(transformComponentDocGenProps);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
component,
|
|
193
|
+
hasArgAsSlot,
|
|
194
|
+
hasArgAsProp,
|
|
195
|
+
argAsProp
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
const AdditionalApiDocs = ({ children })=>{
|
|
199
|
+
const styles = useStyles();
|
|
200
|
+
return /*#__PURE__*/ _react.createElement("div", {
|
|
201
|
+
className: styles.additionalInfo
|
|
202
|
+
}, /*#__PURE__*/ _react.createElement("div", {
|
|
203
|
+
className: styles.additionalInfoMessage
|
|
204
|
+
}, /*#__PURE__*/ _react.createElement(_reacticons.InfoFilled, {
|
|
205
|
+
className: styles.additionalInfoIcon
|
|
206
|
+
}), /*#__PURE__*/ _react.createElement("div", {
|
|
207
|
+
className: styles.infoIcon
|
|
208
|
+
}, children)));
|
|
209
|
+
};
|
|
210
|
+
const RenderArgsTable = ({ story, hideArgsTable, showSlotsApi, showNativePropsApi })=>{
|
|
211
|
+
const { component, hasArgAsProp, hasArgAsSlot, argAsProp } = withSlotEnhancer(story, {
|
|
212
|
+
slotsApi: showSlotsApi,
|
|
213
|
+
nativePropsApi: showNativePropsApi
|
|
214
|
+
});
|
|
215
|
+
const styles = useStyles();
|
|
216
|
+
return hideArgsTable ? null : /*#__PURE__*/ _react.createElement(_react.Fragment, null, /*#__PURE__*/ _react.createElement("div", {
|
|
217
|
+
className: styles.additionalInfoWrapper
|
|
218
|
+
}, hasArgAsProp && /*#__PURE__*/ _react.createElement(AdditionalApiDocs, null, /*#__PURE__*/ _react.createElement("p", null, /*#__PURE__*/ _react.createElement("b", null, "Native props are supported ", /*#__PURE__*/ _react.createElement("span", {
|
|
219
|
+
role: "presentation"
|
|
220
|
+
}, "🙌"), /*#__PURE__*/ _react.createElement("br", null)), /*#__PURE__*/ _react.createElement("span", null, "All HTML attributes native to the", getNativeElementsList(argAsProp), ", including all ", /*#__PURE__*/ _react.createElement("code", null, "aria-*"), " and ", /*#__PURE__*/ _react.createElement("code", null, "data-*"), ' ', "attributes, can be applied as native props on this component."))), hasArgAsSlot && /*#__PURE__*/ _react.createElement(AdditionalApiDocs, null, /*#__PURE__*/ _react.createElement("p", null, /*#__PURE__*/ _react.createElement("b", null, "Customizing components with slots ", /*#__PURE__*/ _react.createElement("span", {
|
|
221
|
+
role: "presentation"
|
|
222
|
+
}, "🙌")), /*#__PURE__*/ _react.createElement("br", null), /*#__PURE__*/ _react.createElement("span", null, "Slots in Fluent UI React components are designed to be modified or replaced, providing a flexible approach to customizing components. Each slot is exposed as a top-level prop and can be filled with primitive values, JSX/TSX, props objects, or render functions. This allows for more dynamic and reusable component structures, similar to slots in other frameworks.", ' ', /*#__PURE__*/ _react.createElement(_reactlink.Link, {
|
|
223
|
+
href: "/?path=/docs/concepts-developer-customizing-components-with-slots--docs"
|
|
224
|
+
}, "Customizing components with slots", ' '))))), /*#__PURE__*/ _react.createElement(_blocks.ArgTypes, {
|
|
225
|
+
of: component
|
|
226
|
+
}));
|
|
227
|
+
};
|
|
228
|
+
const RenderPrimaryStory = ({ primaryStory, skipPrimaryStory })=>{
|
|
229
|
+
const styles = useStyles();
|
|
230
|
+
return skipPrimaryStory ? null : /*#__PURE__*/ _react.createElement(_react.Fragment, null, /*#__PURE__*/ _react.createElement("hr", {
|
|
231
|
+
className: styles.divider
|
|
232
|
+
}), /*#__PURE__*/ _react.createElement(_blocks.HeaderMdx, {
|
|
233
|
+
as: "h3",
|
|
234
|
+
id: (0, _Toc.nameToHash)(primaryStory.name)
|
|
235
|
+
}, primaryStory.name), /*#__PURE__*/ _react.createElement(_blocks.Primary, null));
|
|
236
|
+
};
|
|
237
|
+
const FluentDocsPage = ()=>{
|
|
238
|
+
var _primaryStoryContext_parameters, _primaryStoryContext_globals, _primaryStoryContext_parameters_docs, _primaryStoryContext_parameters1, _primaryStoryContext_parameters_docs1, _primaryStoryContext_parameters2, _primaryStoryContext_parameters3;
|
|
239
|
+
const context = _react.useContext(_blocks.DocsContext);
|
|
240
|
+
// Get the fluent docs page configuration from context
|
|
241
|
+
const docsPageConfig = (0, _utils.getDocsPageConfig)(context);
|
|
242
|
+
const stories = context.componentStories();
|
|
243
|
+
const primaryStory = stories[0];
|
|
244
|
+
const primaryStoryContext = context.getStoryContext(primaryStory);
|
|
245
|
+
assertStoryMetaValues(primaryStory);
|
|
246
|
+
var _primaryStoryContext_parameters_dir, _ref;
|
|
247
|
+
const dir = (_ref = (_primaryStoryContext_parameters_dir = (_primaryStoryContext_parameters = primaryStoryContext.parameters) === null || _primaryStoryContext_parameters === void 0 ? void 0 : _primaryStoryContext_parameters.dir) !== null && _primaryStoryContext_parameters_dir !== void 0 ? _primaryStoryContext_parameters_dir : (_primaryStoryContext_globals = primaryStoryContext.globals) === null || _primaryStoryContext_globals === void 0 ? void 0 : _primaryStoryContext_globals[_constants.DIR_ID]) !== null && _ref !== void 0 ? _ref : 'ltr';
|
|
248
|
+
const selectedTheme = _theme.themes.find((theme)=>theme.id === primaryStoryContext.globals[_constants.THEME_ID]);
|
|
249
|
+
const hideArgsTable = Boolean((_primaryStoryContext_parameters1 = primaryStoryContext.parameters) === null || _primaryStoryContext_parameters1 === void 0 ? void 0 : (_primaryStoryContext_parameters_docs = _primaryStoryContext_parameters1.docs) === null || _primaryStoryContext_parameters_docs === void 0 ? void 0 : _primaryStoryContext_parameters_docs.hideArgsTable);
|
|
250
|
+
const skipPrimaryStory = Boolean((_primaryStoryContext_parameters2 = primaryStoryContext.parameters) === null || _primaryStoryContext_parameters2 === void 0 ? void 0 : (_primaryStoryContext_parameters_docs1 = _primaryStoryContext_parameters2.docs) === null || _primaryStoryContext_parameters_docs1 === void 0 ? void 0 : _primaryStoryContext_parameters_docs1.skipPrimaryStory);
|
|
251
|
+
var _primaryStoryContext_parameters_videos;
|
|
252
|
+
const videos = (_primaryStoryContext_parameters_videos = (_primaryStoryContext_parameters3 = primaryStoryContext.parameters) === null || _primaryStoryContext_parameters3 === void 0 ? void 0 : _primaryStoryContext_parameters3.videos) !== null && _primaryStoryContext_parameters_videos !== void 0 ? _primaryStoryContext_parameters_videos : null;
|
|
253
|
+
const styles = useStyles();
|
|
254
|
+
// If docs page is disabled, return Storybook's default docs page
|
|
255
|
+
if (!docsPageConfig) {
|
|
256
|
+
return /*#__PURE__*/ _react.createElement("div", {
|
|
257
|
+
className: "sb-unstyled"
|
|
258
|
+
}, /*#__PURE__*/ _react.createElement(_blocks.Title, null), /*#__PURE__*/ _react.createElement(_blocks.Subtitle, null), /*#__PURE__*/ _react.createElement(_blocks.Description, null), /*#__PURE__*/ _react.createElement(RenderPrimaryStory, {
|
|
259
|
+
primaryStory: primaryStory,
|
|
260
|
+
skipPrimaryStory: skipPrimaryStory
|
|
261
|
+
}), /*#__PURE__*/ _react.createElement(RenderArgsTable, {
|
|
262
|
+
story: primaryStory,
|
|
263
|
+
hideArgsTable: hideArgsTable
|
|
264
|
+
}), /*#__PURE__*/ _react.createElement(_blocks.Stories, null));
|
|
265
|
+
}
|
|
266
|
+
// Determine what to show based on configuration
|
|
267
|
+
const { tableOfContents: showTableOfContents, dirSwitcher: showDirSwitcher, themePicker: showThemePicker, copyAsMarkdown: showCopyAsMarkdown, argTable } = docsPageConfig;
|
|
268
|
+
// DEBUG
|
|
269
|
+
// console.log('FluentDocsPage', context);
|
|
270
|
+
// console.table(stories.map((s: StoreItem) => ({ id: s.id, kind: s.kind, name: s.name, story: s.story })));
|
|
271
|
+
// console.table(
|
|
272
|
+
// Object.values((context as any).argTypes).map(arg => ({
|
|
273
|
+
// name: arg.name,
|
|
274
|
+
// description: arg.description,
|
|
275
|
+
// type: arg.table?.type?.summary ?? '?',
|
|
276
|
+
// default: arg.table?.defaultValue?.summary ?? '-',
|
|
277
|
+
// })),
|
|
278
|
+
// );
|
|
279
|
+
return /*#__PURE__*/ _react.createElement("div", {
|
|
280
|
+
className: "sb-unstyled"
|
|
281
|
+
}, /*#__PURE__*/ _react.createElement(_blocks.Title, null), /*#__PURE__*/ _react.createElement("div", {
|
|
282
|
+
className: styles.wrapper
|
|
283
|
+
}, /*#__PURE__*/ _react.createElement("div", {
|
|
284
|
+
className: styles.container
|
|
285
|
+
}, (showThemePicker || showDirSwitcher || showCopyAsMarkdown) && /*#__PURE__*/ _react.createElement("div", {
|
|
286
|
+
className: styles.globalTogglesContainer
|
|
287
|
+
}, showThemePicker && /*#__PURE__*/ _react.createElement(_ThemePicker.ThemePicker, {
|
|
288
|
+
selectedThemeId: selectedTheme === null || selectedTheme === void 0 ? void 0 : selectedTheme.id
|
|
289
|
+
}), showDirSwitcher && /*#__PURE__*/ _react.createElement(_DirSwitch.DirSwitch, {
|
|
290
|
+
dir: dir
|
|
291
|
+
}), showCopyAsMarkdown && /*#__PURE__*/ _react.createElement(_CopyAsMarkdownButton.CopyAsMarkdownButton, {
|
|
292
|
+
storyId: primaryStory.id
|
|
293
|
+
})), /*#__PURE__*/ _react.createElement(_blocks.Subtitle, null), /*#__PURE__*/ _react.createElement("div", {
|
|
294
|
+
className: styles.description
|
|
295
|
+
}, /*#__PURE__*/ _react.createElement(_blocks.Description, null), videos && /*#__PURE__*/ _react.createElement(VideoPreviews, {
|
|
296
|
+
videos: videos
|
|
297
|
+
})), /*#__PURE__*/ _react.createElement(RenderPrimaryStory, {
|
|
298
|
+
primaryStory: primaryStory,
|
|
299
|
+
skipPrimaryStory: skipPrimaryStory
|
|
300
|
+
}), /*#__PURE__*/ _react.createElement(RenderArgsTable, {
|
|
301
|
+
story: primaryStory,
|
|
302
|
+
hideArgsTable: hideArgsTable,
|
|
303
|
+
showSlotsApi: argTable.slotsApi,
|
|
304
|
+
showNativePropsApi: argTable.nativePropsApi
|
|
305
|
+
}), /*#__PURE__*/ _react.createElement(_blocks.Stories, null)), showTableOfContents && /*#__PURE__*/ _react.createElement("div", {
|
|
306
|
+
className: styles.toc
|
|
307
|
+
}, /*#__PURE__*/ _react.createElement(_Toc.Toc, {
|
|
308
|
+
stories: stories
|
|
309
|
+
}))));
|
|
310
|
+
};
|
|
311
|
+
function assertStoryMetaValues(story) {
|
|
312
|
+
if (story.component === null) {
|
|
313
|
+
throw new Error([
|
|
314
|
+
'🚨 Invalid Story Meta declaration:',
|
|
315
|
+
`- primaryStory.component of componentId:${story.componentId} is "null"`,
|
|
316
|
+
'- to resolve this error, please update "component" property value in your story definition to reference a React Component or remove it if it is not needed.'
|
|
317
|
+
].join('\n'));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/docs/FluentDocsPage.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n DocsContext,\n ArgTypes,\n Title,\n Subtitle,\n Description,\n HeaderMdx,\n Primary,\n Stories,\n type DocsContextProps,\n} from '@storybook/addon-docs/blocks';\nimport type { PreparedStory, Renderer, SBEnumType } from 'storybook/internal/types';\n\nimport { tokens } from '@fluentui/react-theme';\nimport { Link } from '@fluentui/react-link';\nimport { Text } from '@fluentui/react-text';\nimport { makeStyles } from '@griffel/react';\nimport { InfoFilled } from '@fluentui/react-icons';\nimport type { JSXElement } from '@fluentui/react-utilities';\n\nimport { DIR_ID, THEME_ID } from '../constants';\nimport { themes } from '../theme';\n\nimport { getDocsPageConfig } from './utils';\nimport { DirSwitch } from './DirSwitch';\nimport { ThemePicker } from './ThemePicker';\nimport { Toc, nameToHash } from './Toc';\nimport { CopyAsMarkdownButton } from './CopyAsMarkdownButton';\n\ntype PrimaryStory = PreparedStory<Renderer>;\n\nconst useStyles = makeStyles({\n divider: {\n height: '1px',\n backgroundColor: '#e1dfdd',\n border: '0px none',\n margin: '48px 0px',\n },\n wrapper: {\n display: 'flex',\n gap: '16px',\n },\n toc: {\n flexBasis: '200px',\n flexShrink: 0,\n [`@media screen and (max-width: 1000px)`]: {\n display: 'none',\n },\n },\n container: {\n // without a width, this div grows wider than its parent\n width: '200px',\n flexGrow: 1,\n },\n globalTogglesContainer: {\n columnGap: tokens.spacingHorizontalXXXL,\n display: 'flex',\n },\n description: {\n display: 'grid',\n gridTemplateColumns: '1fr min-content',\n },\n additionalInfoWrapper: {\n display: 'flex',\n flexDirection: 'column',\n gap: tokens.spacingVerticalM,\n },\n additionalInfo: {\n display: 'flex',\n flexDirection: 'column',\n gap: tokens.spacingVerticalM,\n border: `1px solid ${tokens.colorNeutralStroke1}`,\n borderRadius: tokens.borderRadiusMedium,\n padding: tokens.spacingHorizontalM,\n margin: `0 ${tokens.spacingHorizontalM}`,\n },\n additionalInfoIcon: {\n alignSelf: 'center',\n color: tokens.colorBrandForeground1,\n fontSize: '24px',\n marginRight: tokens.spacingHorizontalM,\n },\n additionalInfoMessage: {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'center',\n gap: tokens.spacingVerticalXS,\n },\n infoIcon: {\n display: 'flex',\n flexDirection: 'column',\n gap: tokens.spacingVerticalXS,\n flex: 1,\n },\n});\n\nconst useVideoClasses = makeStyles({\n container: {\n display: 'flex',\n flexDirection: 'column',\n gap: tokens.spacingHorizontalMNudge,\n },\n preview: {\n borderRadius: tokens.borderRadiusSmall,\n display: 'flex',\n flexDirection: 'column',\n gap: tokens.spacingHorizontalM,\n padding: tokens.spacingHorizontalM,\n backgroundColor: tokens.colorNeutralBackground2,\n\n ':hover': {\n backgroundColor: tokens.colorNeutralBackground2Hover,\n },\n },\n image: {\n width: '200px',\n },\n});\n\nconst VideoPreviews: React.FC<{\n videos: {\n href: string;\n preview: string;\n source: 'youtube';\n title: string;\n }[];\n}> = props => {\n const { videos } = props;\n const classes = useVideoClasses();\n\n return (\n <div className={classes.container}>\n {videos.map(video => (\n <Link className={classes.preview} href={video.href} target=\"_blank\" key={video.href}>\n <img alt={`Video: ${video.preview}`} src={video.preview} className={classes.image} />\n <Text>{video.title}</Text>\n </Link>\n ))}\n </div>\n );\n};\n\nconst getNativeElementsList = (elements: SBEnumType['value']): React.ReactElement => {\n const elementsArr = elements?.map((el, idx) => [\n <code key={idx}>{`<${el}>`}</code>,\n idx !== elements.length - 1 ? ', ' : ' ',\n ]);\n\n return (\n <>\n {elementsArr}\n {elementsArr.length > 1 ? 'elements' : 'element'}\n </>\n );\n};\n\nconst slotRegex = /as\\?:\\s*\"([^\"]+)\"/;\n/**\n * NOTE: this function mutates original story argTypes including all story subcomponents if they are present\n */\nfunction withSlotEnhancer(story: PreparedStory, options: { slotsApi?: boolean; nativePropsApi?: boolean }) {\n const hasArgAsProp = options.nativePropsApi ? story.argTypes.as?.type?.name === 'enum' : false;\n const argAsProp = hasArgAsProp ? (story.argTypes.as.type as SBEnumType).value : null;\n let hasArgAsSlot = false;\n\n type ArgTypes = Record<\n string,\n {\n table?: { type: { summary?: string } };\n type: { name?: string };\n }\n >;\n\n type InternalComponentApi = {\n __docgenInfo: {\n props?: ArgTypes;\n };\n };\n\n const transformArgTypeNameWithSlotShorthand = (typeName: string) => {\n const match = typeName.match(slotRegex);\n\n if (match) {\n hasArgAsSlot = true;\n return `Slot<\\\"${match[1]}\\\">`;\n }\n\n if (typeName.includes('WithSlotShorthandValue')) {\n hasArgAsSlot = true;\n return `Slot`;\n }\n\n return typeName;\n };\n\n /**\n * Transform the arg types with slot shorthand (mutates the arg types object reference)\n * This is necessary to ensure that the arg types are correctly displayed in the docs page\n */\n const transformArgTypesWithSlotShorthand = (argTypes: ArgTypes) => {\n Object.values(argTypes).forEach(argType => {\n // Transform the type summary if it exists\n if (argType?.table?.type?.summary) {\n argType.table.type.summary = transformArgTypeNameWithSlotShorthand(argType.table.type.summary);\n }\n // Transform the type name if it exists\n if (argType?.type?.name) {\n argType.type.name = transformArgTypeNameWithSlotShorthand(argType.type.name);\n }\n });\n };\n\n const transformComponentDocGenProps = (component: InternalComponentApi) => {\n const docGenProps = component?.__docgenInfo?.props;\n if (docGenProps) {\n transformArgTypesWithSlotShorthand(docGenProps);\n }\n };\n\n const component = story.moduleExport;\n\n if (options.slotsApi) {\n // Transform the arg types with slot shorthand (mutates the arg types object reference)\n transformArgTypesWithSlotShorthand(story.argTypes as ArgTypes);\n\n // Transform the component doc gen props with slot shorthand (mutates the component doc gen props object reference)\n transformComponentDocGenProps(component);\n\n // Transform the subcomponents doc gen props with slot shorthand\n // (mutates the subcomponents doc gen props object reference)\n if (story.subcomponents) {\n Object.values(story.subcomponents).forEach(transformComponentDocGenProps);\n }\n }\n\n return { component, hasArgAsSlot, hasArgAsProp, argAsProp };\n}\n\nconst AdditionalApiDocs: React.FC<{ children: React.ReactElement | React.ReactElement[] }> = ({ children }) => {\n const styles = useStyles();\n return (\n <div className={styles.additionalInfo}>\n <div className={styles.additionalInfoMessage}>\n <InfoFilled className={styles.additionalInfoIcon} />\n <div className={styles.infoIcon}>{children}</div>\n </div>\n </div>\n );\n};\n\nconst RenderArgsTable = ({\n story,\n hideArgsTable,\n showSlotsApi,\n showNativePropsApi,\n}: {\n story: PrimaryStory;\n hideArgsTable: boolean;\n showSlotsApi?: boolean;\n showNativePropsApi?: boolean;\n}) => {\n const { component, hasArgAsProp, hasArgAsSlot, argAsProp } = withSlotEnhancer(story, {\n slotsApi: showSlotsApi,\n nativePropsApi: showNativePropsApi,\n });\n const styles = useStyles();\n\n return hideArgsTable ? null : (\n <>\n <div className={styles.additionalInfoWrapper}>\n {hasArgAsProp && (\n <AdditionalApiDocs>\n <p>\n <b>\n Native props are supported <span role=\"presentation\">🙌</span>\n <br />\n </b>\n <span>\n All HTML attributes native to the\n {getNativeElementsList(argAsProp!)}, including all <code>aria-*</code> and <code>data-*</code>{' '}\n attributes, can be applied as native props on this component.\n </span>\n </p>\n </AdditionalApiDocs>\n )}\n {hasArgAsSlot && (\n <AdditionalApiDocs>\n <p>\n <b>\n Customizing components with slots <span role=\"presentation\">🙌</span>\n </b>\n <br />\n <span>\n Slots in Fluent UI React components are designed to be modified or replaced, providing a flexible\n approach to customizing components. Each slot is exposed as a top-level prop and can be filled with\n primitive values, JSX/TSX, props objects, or render functions. This allows for more dynamic and reusable\n component structures, similar to slots in other frameworks.{' '}\n <Link href=\"/?path=/docs/concepts-developer-customizing-components-with-slots--docs\">\n Customizing components with slots{' '}\n </Link>\n </span>\n </p>\n </AdditionalApiDocs>\n )}\n </div>\n <ArgTypes of={component} />\n </>\n );\n};\n\nconst RenderPrimaryStory = ({\n primaryStory,\n skipPrimaryStory,\n}: {\n primaryStory: PrimaryStory;\n skipPrimaryStory: boolean;\n}) => {\n const styles = useStyles();\n return skipPrimaryStory ? null : (\n <>\n <hr className={styles.divider} />\n <HeaderMdx as=\"h3\" id={nameToHash(primaryStory.name)}>\n {primaryStory.name}\n </HeaderMdx>\n <Primary />\n </>\n );\n};\n\nexport const FluentDocsPage = (): JSXElement => {\n const context = React.useContext(DocsContext);\n\n // Get the fluent docs page configuration from context\n const docsPageConfig = getDocsPageConfig(context);\n\n const stories = context.componentStories();\n\n const primaryStory = stories[0];\n const primaryStoryContext = context.getStoryContext(primaryStory);\n\n assertStoryMetaValues(primaryStory);\n\n const dir = primaryStoryContext.parameters?.dir ?? primaryStoryContext.globals?.[DIR_ID] ?? 'ltr';\n const selectedTheme = themes.find(theme => theme.id === primaryStoryContext.globals![THEME_ID]);\n\n const hideArgsTable = Boolean(primaryStoryContext.parameters?.docs?.hideArgsTable);\n const skipPrimaryStory = Boolean(primaryStoryContext.parameters?.docs?.skipPrimaryStory);\n\n const videos = primaryStoryContext.parameters?.videos ?? null;\n const styles = useStyles();\n\n // If docs page is disabled, return Storybook's default docs page\n if (!docsPageConfig) {\n return (\n <div className=\"sb-unstyled\">\n <Title />\n <Subtitle />\n <Description />\n <RenderPrimaryStory primaryStory={primaryStory} skipPrimaryStory={skipPrimaryStory} />\n <RenderArgsTable story={primaryStory} hideArgsTable={hideArgsTable} />\n <Stories />\n </div>\n );\n }\n\n // Determine what to show based on configuration\n const {\n tableOfContents: showTableOfContents,\n dirSwitcher: showDirSwitcher,\n themePicker: showThemePicker,\n copyAsMarkdown: showCopyAsMarkdown,\n argTable,\n } = docsPageConfig;\n\n // DEBUG\n // console.log('FluentDocsPage', context);\n // console.table(stories.map((s: StoreItem) => ({ id: s.id, kind: s.kind, name: s.name, story: s.story })));\n // console.table(\n // Object.values((context as any).argTypes).map(arg => ({\n // name: arg.name,\n // description: arg.description,\n // type: arg.table?.type?.summary ?? '?',\n // default: arg.table?.defaultValue?.summary ?? '-',\n // })),\n // );\n\n return (\n <div className=\"sb-unstyled\">\n <Title />\n <div className={styles.wrapper}>\n <div className={styles.container}>\n {(showThemePicker || showDirSwitcher || showCopyAsMarkdown) && (\n <div className={styles.globalTogglesContainer}>\n {showThemePicker && <ThemePicker selectedThemeId={selectedTheme?.id} />}\n {showDirSwitcher && <DirSwitch dir={dir} />}\n {showCopyAsMarkdown && <CopyAsMarkdownButton storyId={primaryStory.id} />}\n </div>\n )}\n <Subtitle />\n <div className={styles.description}>\n <Description />\n {videos && <VideoPreviews videos={videos} />}\n </div>\n <RenderPrimaryStory\n primaryStory={primaryStory as unknown as PrimaryStory}\n skipPrimaryStory={skipPrimaryStory}\n />\n <RenderArgsTable\n story={primaryStory as unknown as PrimaryStory}\n hideArgsTable={hideArgsTable}\n showSlotsApi={argTable.slotsApi}\n showNativePropsApi={argTable.nativePropsApi}\n />\n <Stories />\n </div>\n {showTableOfContents && (\n <div className={styles.toc}>\n <Toc stories={stories} />\n </div>\n )}\n </div>\n </div>\n );\n};\n\nfunction assertStoryMetaValues(story: ReturnType<DocsContextProps['componentStories']>[number]) {\n if (story.component === null) {\n throw new Error(\n [\n '🚨 Invalid Story Meta declaration:',\n `- primaryStory.component of componentId:${story.componentId} is \"null\"`,\n '- to resolve this error, please update \"component\" property value in your story definition to reference a React Component or remove it if it is not needed.',\n ].join('\\n'),\n );\n }\n}\n"],"names":["FluentDocsPage","useStyles","makeStyles","divider","height","backgroundColor","border","margin","wrapper","display","gap","toc","flexBasis","flexShrink","container","width","flexGrow","globalTogglesContainer","columnGap","tokens","spacingHorizontalXXXL","description","gridTemplateColumns","additionalInfoWrapper","flexDirection","spacingVerticalM","additionalInfo","colorNeutralStroke1","borderRadius","borderRadiusMedium","padding","spacingHorizontalM","additionalInfoIcon","alignSelf","color","colorBrandForeground1","fontSize","marginRight","additionalInfoMessage","alignItems","spacingVerticalXS","infoIcon","flex","useVideoClasses","spacingHorizontalMNudge","preview","borderRadiusSmall","colorNeutralBackground2","colorNeutralBackground2Hover","image","VideoPreviews","props","videos","classes","div","className","map","video","Link","href","target","key","img","alt","src","Text","title","getNativeElementsList","elements","elementsArr","el","idx","code","length","slotRegex","withSlotEnhancer","story","options","hasArgAsProp","nativePropsApi","argTypes","as","type","name","argAsProp","value","hasArgAsSlot","transformArgTypeNameWithSlotShorthand","typeName","match","includes","transformArgTypesWithSlotShorthand","Object","values","forEach","argType","table","summary","transformComponentDocGenProps","component","docGenProps","__docgenInfo","moduleExport","slotsApi","subcomponents","AdditionalApiDocs","children","styles","InfoFilled","RenderArgsTable","hideArgsTable","showSlotsApi","showNativePropsApi","p","b","span","role","br","ArgTypes","of","RenderPrimaryStory","primaryStory","skipPrimaryStory","hr","HeaderMdx","id","nameToHash","Primary","primaryStoryContext","context","React","useContext","DocsContext","docsPageConfig","getDocsPageConfig","stories","componentStories","getStoryContext","assertStoryMetaValues","dir","parameters","globals","DIR_ID","selectedTheme","themes","find","theme","THEME_ID","Boolean","docs","Title","Subtitle","Description","Stories","tableOfContents","showTableOfContents","dirSwitcher","showDirSwitcher","themePicker","showThemePicker","copyAsMarkdown","showCopyAsMarkdown","argTable","ThemePicker","selectedThemeId","DirSwitch","CopyAsMarkdownButton","storyId","Toc","Error","componentId","join"],"mappings":";;;;+BA0UaA;;;eAAAA;;;;iEA1UU;wBAWhB;4BAGgB;2BACF;2BACA;wBACM;4BACA;2BAG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C,eAAe,EAAErB,0BAAAA,oCAAAA,cAAelB,EAAE;QAClEgC,iCAAmB,qBAACQ,oBAAS;QAAC1B,KAAKA;QACnCsB,oCAAsB,qBAACK,0CAAoB;QAACC,SAAS9C,aAAaI,EAAE;uBAGzE,qBAAC0B,gBAAQ,uBACT,qBAACjG;QAAIC,WAAWoD,OAAOtF,WAAW;qBAChC,qBAACmI,mBAAW,SACXpG,wBAAU,qBAACF;QAAcE,QAAQA;uBAEpC,qBAACoE;QACCC,cAAcA;QACdC,kBAAkBA;sBAEpB,qBAACb;QACCjC,OAAO6C;QACPX,eAAeA;QACfC,cAAcmD,SAAS3D,QAAQ;QAC/BS,oBAAoBkD,SAASnF,cAAc;sBAE7C,qBAAC0E,eAAO,UAETE,qCACC,qBAACrG;QAAIC,WAAWoD,OAAOhG,GAAG;qBACxB,qBAAC6J,QAAG;QAACjC,SAASA;;AAM1B;AAEA,SAASG,sBAAsB9D,KAA+D;IAC5F,IAAIA,MAAMuB,SAAS,KAAK,MAAM;QAC5B,MAAM,IAAIsE,MACR;YACE;YACA,CAAC,wCAAwC,EAAE7F,MAAM8F,WAAW,CAAC,UAAU,CAAC;YACxE;SACD,CAACC,IAAI,CAAC;IAEX;AACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "FluentStory", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return FluentStory;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
|
+
const iframeStyle = {
|
|
14
|
+
width: '100%',
|
|
15
|
+
border: 'none'
|
|
16
|
+
};
|
|
17
|
+
const FluentStory = ({ id, height })=>{
|
|
18
|
+
return /*#__PURE__*/ _react.createElement("div", {
|
|
19
|
+
className: "sb-story sb-unstyled"
|
|
20
|
+
}, /*#__PURE__*/ _react.createElement("iframe", {
|
|
21
|
+
title: id,
|
|
22
|
+
src: `iframe.html?id=${id}&mode=story`,
|
|
23
|
+
style: iframeStyle,
|
|
24
|
+
height: height
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/docs/FluentStory.tsx"],"sourcesContent":["import * as React from 'react';\nimport type { JSXElement } from '@fluentui/react-utilities';\n\nconst iframeStyle: React.CSSProperties = {\n width: '100%',\n border: 'none',\n};\n\ntype FluentStoryProps = {\n /** The unique identifier for the story */\n id: string;\n /** The height of the iframe */\n height?: string | number;\n};\n\n/**\n * Story component to render stories in an iframe.\n * Provides a similar experience to Storybook's v7 `Story` component.\n */\nexport const FluentStory = ({ id, height }: FluentStoryProps): JSXElement => {\n return (\n <div className=\"sb-story sb-unstyled\">\n <iframe title={id} src={`iframe.html?id=${id}&mode=story`} style={iframeStyle} height={height} />\n </div>\n );\n};\n"],"names":["FluentStory","iframeStyle","width","border","id","height","div","className","iframe","title","src","style"],"mappings":";;;;+BAmBaA;;;eAAAA;;;;iEAnBU;AAGvB,MAAMC,cAAmC;IACvCC,OAAO;IACPC,QAAQ;AACV;AAaO,MAAMH,cAAc,CAAC,EAAEI,EAAE,EAAEC,MAAM,EAAoB;IAC1D,qBACE,qBAACC;QAAIC,WAAU;qBACb,qBAACC;QAAOC,OAAOL;QAAIM,KAAK,CAAC,eAAe,EAAEN,GAAG,WAAW,CAAC;QAAEO,OAAOV;QAAaI,QAAQA;;AAG7F"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "ThemePicker", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return ThemePicker;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
12
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
13
|
+
const _previewapi = require("storybook/preview-api");
|
|
14
|
+
const _reactmenu = require("@fluentui/react-menu");
|
|
15
|
+
const _reactbutton = require("@fluentui/react-button");
|
|
16
|
+
const _react1 = require("@griffel/react");
|
|
17
|
+
const _ = require("..");
|
|
18
|
+
const useStyles = (0, _react1.makeStyles)({
|
|
19
|
+
menuButton: {
|
|
20
|
+
minWidth: '210px',
|
|
21
|
+
justifyContent: 'flex-start'
|
|
22
|
+
},
|
|
23
|
+
chevronIcon: {
|
|
24
|
+
marginLeft: 'auto'
|
|
25
|
+
},
|
|
26
|
+
menuPopover: {
|
|
27
|
+
minWidth: '210px'
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const ThemePicker = ({ selectedThemeId })=>{
|
|
31
|
+
const styles = useStyles();
|
|
32
|
+
const [currentThemeId, setCurrentThemeId] = _react.useState(selectedThemeId !== null && selectedThemeId !== void 0 ? selectedThemeId : null);
|
|
33
|
+
const setGlobalTheme = (themeId)=>{
|
|
34
|
+
_previewapi.addons.getChannel().emit('updateGlobals', {
|
|
35
|
+
globals: {
|
|
36
|
+
[_.THEME_ID]: themeId
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
const onCheckedValueChange = (e, data)=>{
|
|
41
|
+
const newThemeId = data.checkedItems[0];
|
|
42
|
+
setGlobalTheme(newThemeId);
|
|
43
|
+
setCurrentThemeId(newThemeId);
|
|
44
|
+
};
|
|
45
|
+
const selectedTheme = _.themes.find((theme)=>theme.id === currentThemeId);
|
|
46
|
+
var _selectedTheme_label;
|
|
47
|
+
return /*#__PURE__*/ _react.createElement(_reactmenu.Menu, {
|
|
48
|
+
// eslint-disable-next-line react/jsx-no-bind
|
|
49
|
+
onCheckedValueChange: onCheckedValueChange,
|
|
50
|
+
checkedValues: {
|
|
51
|
+
theme: selectedThemeId ? [
|
|
52
|
+
selectedThemeId
|
|
53
|
+
] : []
|
|
54
|
+
},
|
|
55
|
+
positioning: {
|
|
56
|
+
autoSize: true
|
|
57
|
+
}
|
|
58
|
+
}, /*#__PURE__*/ _react.createElement(_reactmenu.MenuTrigger, null, /*#__PURE__*/ _react.createElement(_reactbutton.MenuButton, {
|
|
59
|
+
className: styles.menuButton,
|
|
60
|
+
menuIcon: {
|
|
61
|
+
className: styles.chevronIcon
|
|
62
|
+
}
|
|
63
|
+
}, (_selectedTheme_label = selectedTheme === null || selectedTheme === void 0 ? void 0 : selectedTheme.label) !== null && _selectedTheme_label !== void 0 ? _selectedTheme_label : 'Theme')), /*#__PURE__*/ _react.createElement(_reactmenu.MenuPopover, {
|
|
64
|
+
className: styles.menuPopover
|
|
65
|
+
}, /*#__PURE__*/ _react.createElement(_reactmenu.MenuList, null, _.themes.map((theme)=>/*#__PURE__*/ _react.createElement(_reactmenu.MenuItemRadio, {
|
|
66
|
+
name: "theme",
|
|
67
|
+
value: theme.id,
|
|
68
|
+
key: theme.id
|
|
69
|
+
}, theme.label)))));
|
|
70
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/docs/ThemePicker.tsx"],"sourcesContent":["import * as React from 'react';\nimport { addons } from 'storybook/preview-api';\n\nimport { Menu, MenuItemRadio, MenuList, MenuPopover, MenuTrigger } from '@fluentui/react-menu';\nimport type { MenuProps } from '@fluentui/react-menu';\nimport { MenuButton } from '@fluentui/react-button';\nimport { makeStyles } from '@griffel/react';\n\nimport { themes, ThemeIds, THEME_ID } from '..';\n\nconst useStyles = makeStyles({\n menuButton: {\n minWidth: '210px',\n justifyContent: 'flex-start',\n },\n\n chevronIcon: {\n marginLeft: 'auto',\n },\n\n menuPopover: {\n minWidth: '210px',\n },\n});\n\n/**\n * Theme picker used in the react-components docs header\n */\nexport const ThemePicker: React.FC<{ selectedThemeId?: string }> = ({ selectedThemeId }) => {\n const styles = useStyles();\n const [currentThemeId, setCurrentThemeId] = React.useState(selectedThemeId ?? null);\n\n const setGlobalTheme = (themeId: ThemeIds): void => {\n addons.getChannel().emit('updateGlobals', { globals: { [THEME_ID]: themeId } });\n };\n const onCheckedValueChange: MenuProps['onCheckedValueChange'] = (e, data) => {\n const newThemeId = data.checkedItems[0] as ThemeIds;\n setGlobalTheme(newThemeId);\n setCurrentThemeId(newThemeId);\n };\n\n const selectedTheme = themes.find(theme => theme.id === currentThemeId);\n\n return (\n <Menu\n // eslint-disable-next-line react/jsx-no-bind\n onCheckedValueChange={onCheckedValueChange}\n checkedValues={{ theme: selectedThemeId ? [selectedThemeId] : [] }}\n positioning={{ autoSize: true }}\n >\n <MenuTrigger>\n <MenuButton className={styles.menuButton} menuIcon={{ className: styles.chevronIcon }}>\n {selectedTheme?.label ?? 'Theme'}\n </MenuButton>\n </MenuTrigger>\n <MenuPopover className={styles.menuPopover}>\n <MenuList>\n {themes.map(theme => (\n <MenuItemRadio name=\"theme\" value={theme.id} key={theme.id}>\n {theme.label}\n </MenuItemRadio>\n ))}\n </MenuList>\n </MenuPopover>\n </Menu>\n );\n};\n"],"names":["ThemePicker","useStyles","makeStyles","menuButton","minWidth","justifyContent","chevronIcon","marginLeft","menuPopover","selectedThemeId","styles","currentThemeId","setCurrentThemeId","React","useState","setGlobalTheme","themeId","addons","getChannel","emit","globals","THEME_ID","onCheckedValueChange","e","data","newThemeId","checkedItems","selectedTheme","themes","find","theme","id","Menu","checkedValues","positioning","autoSize","MenuTrigger","MenuButton","className","menuIcon","label","MenuPopover","MenuList","map","MenuItemRadio","name","value","key"],"mappings":";;;;+BA4BaA;;;eAAAA;;;;iEA5BU;4BACA;2BAEiD;6BAE7C;wBACA;kBAEgB;AAE3C,MAAMC,YAAYC,IAAAA,kBAAU,EAAC;IAC3BC,YAAY;QACVC,UAAU;QACVC,gBAAgB;IAClB;IAEAC,aAAa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", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
Toc: function() {
|
|
13
|
+
return Toc;
|
|
14
|
+
},
|
|
15
|
+
nameToHash: function() {
|
|
16
|
+
return nameToHash;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
20
|
+
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
21
|
+
const _managerapi = require("storybook/manager-api");
|
|
22
|
+
const _coreevents = require("storybook/internal/core-events");
|
|
23
|
+
const _react1 = require("@griffel/react");
|
|
24
|
+
const useTocStyles = (0, _react1.makeStyles)({
|
|
25
|
+
root: {
|
|
26
|
+
top: '64px',
|
|
27
|
+
position: 'sticky',
|
|
28
|
+
marginLeft: '40px'
|
|
29
|
+
},
|
|
30
|
+
heading: {
|
|
31
|
+
fontSize: '11px',
|
|
32
|
+
fontWeight: 'bold',
|
|
33
|
+
textTransform: 'uppercase',
|
|
34
|
+
marginBottom: '20px'
|
|
35
|
+
},
|
|
36
|
+
ol: {
|
|
37
|
+
position: 'relative',
|
|
38
|
+
listStyleType: 'none',
|
|
39
|
+
marginLeft: 0,
|
|
40
|
+
marginTop: 0,
|
|
41
|
+
paddingInlineStart: '20px',
|
|
42
|
+
'& li': {
|
|
43
|
+
marginBottom: '15px',
|
|
44
|
+
lineHeight: '16px'
|
|
45
|
+
},
|
|
46
|
+
'& a': {
|
|
47
|
+
textDecorationLine: 'none',
|
|
48
|
+
color: '#201F1E',
|
|
49
|
+
fontSize: '14px',
|
|
50
|
+
':hover': {
|
|
51
|
+
color: '#201F1E'
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
'&:before': {
|
|
55
|
+
content: '""',
|
|
56
|
+
position: 'absolute',
|
|
57
|
+
left: 0,
|
|
58
|
+
height: '100%',
|
|
59
|
+
width: '3px',
|
|
60
|
+
backgroundColor: '#EDEBE9',
|
|
61
|
+
borderRadius: '4px'
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
selected: {
|
|
65
|
+
position: 'relative',
|
|
66
|
+
'&:after': {
|
|
67
|
+
content: '""',
|
|
68
|
+
position: 'absolute',
|
|
69
|
+
left: '-20px',
|
|
70
|
+
top: 0,
|
|
71
|
+
bottom: 0,
|
|
72
|
+
width: '3px',
|
|
73
|
+
backgroundColor: '#436DCD',
|
|
74
|
+
borderRadius: '4px'
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
// // Alternative approach to navigate - rerenders the iframe
|
|
79
|
+
// // Usage: selectStory({ story: s.name, kind: s.kind });
|
|
80
|
+
// const selectStory = (story: { kind: string; story: string }) => {
|
|
81
|
+
// console.log('Select Story', story);
|
|
82
|
+
// addons.getChannel().emit(SELECT_STORY, story);
|
|
83
|
+
// };
|
|
84
|
+
const navigate = (url)=>{
|
|
85
|
+
_managerapi.addons.getChannel().emit(_coreevents.NAVIGATE_URL, url);
|
|
86
|
+
};
|
|
87
|
+
const nameToHash = (id)=>id.toLowerCase().replace(/[^a-z0-9]/gi, '-');
|
|
88
|
+
const Toc = ({ stories })=>{
|
|
89
|
+
const [selected, setSelected] = _react.useState('');
|
|
90
|
+
const isNavigating = _react.useRef(false);
|
|
91
|
+
_react.useEffect(()=>{
|
|
92
|
+
// eslint-disable-next-line @nx/workspace-no-restricted-globals
|
|
93
|
+
const observer = new IntersectionObserver((entries)=>{
|
|
94
|
+
if (isNavigating.current) {
|
|
95
|
+
isNavigating.current = false;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
for (const entry of entries){
|
|
99
|
+
const { intersectionRatio, target } = entry;
|
|
100
|
+
if (intersectionRatio > 0.5) {
|
|
101
|
+
setSelected(target.id);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
threshold: [
|
|
107
|
+
0.5
|
|
108
|
+
]
|
|
109
|
+
});
|
|
110
|
+
stories.forEach((link)=>{
|
|
111
|
+
// eslint-disable-next-line @nx/workspace-no-restricted-globals
|
|
112
|
+
const element = document.getElementById(nameToHash(link.name));
|
|
113
|
+
if (element) {
|
|
114
|
+
observer.observe(element);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return ()=>observer.disconnect();
|
|
118
|
+
}, [
|
|
119
|
+
stories
|
|
120
|
+
]);
|
|
121
|
+
const tocItems = stories.map((item)=>{
|
|
122
|
+
return {
|
|
123
|
+
...item,
|
|
124
|
+
selected: nameToHash(item.name) === selected
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
const tocClasses = useTocStyles();
|
|
128
|
+
return /*#__PURE__*/ _react.createElement("nav", {
|
|
129
|
+
className: tocClasses.root
|
|
130
|
+
}, /*#__PURE__*/ _react.createElement("h3", {
|
|
131
|
+
className: tocClasses.heading
|
|
132
|
+
}, "On this page"), /*#__PURE__*/ _react.createElement("ol", {
|
|
133
|
+
className: tocClasses.ol
|
|
134
|
+
}, tocItems.map((s)=>{
|
|
135
|
+
const name = nameToHash(s.name);
|
|
136
|
+
return /*#__PURE__*/ _react.createElement("li", {
|
|
137
|
+
className: s.selected ? tocClasses.selected : '',
|
|
138
|
+
key: s.id
|
|
139
|
+
}, /*#__PURE__*/ _react.createElement("a", {
|
|
140
|
+
href: `#${name}`,
|
|
141
|
+
target: "_self",
|
|
142
|
+
onClick: (e)=>{
|
|
143
|
+
isNavigating.current = true;
|
|
144
|
+
navigate(`#${name}`);
|
|
145
|
+
setSelected(name);
|
|
146
|
+
}
|
|
147
|
+
}, s.name));
|
|
148
|
+
})));
|
|
149
|
+
};
|