diff --git a/CHANGELOG.md b/CHANGELOG.md index c5da183949..c639058b3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Add prototype for expandable control messages in `Chat` @sophieH29 ([#1765](https://github.com/stardust-ui/react/pull/1765)) - Remove Font Awesome icons from docs examples @lucivpav ([#1764](https://github.com/stardust-ui/react/pull/1764)) - Improve QuickStart code example @lucivpav ([#1797](https://github.com/stardust-ui/react/pull/1797)) +- Implement component tab UI @lucivpav ([#1784](https://github.com/stardust-ui/react/pull/1784)) ## [v0.36.2](https://github.com/stardust-ui/react/tree/v0.36.1) (2019-08-19) diff --git a/docs/src/components/ComponentDoc/ComponentBestPractices.tsx b/docs/src/components/ComponentDoc/ComponentBestPractices.tsx new file mode 100644 index 0000000000..76a56b27c3 --- /dev/null +++ b/docs/src/components/ComponentDoc/ComponentBestPractices.tsx @@ -0,0 +1,40 @@ +import * as _ from 'lodash' +import * as PropTypes from 'prop-types' +import * as React from 'react' + +import { exampleBestPracticesContext } from 'docs/src/utils' +import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' + +interface ComponentBestPracticesProps { + displayName: string +} + +export default class ComponentBestPractices extends React.Component< + ComponentBestPracticesProps, + any +> { + static propTypes = { + displayName: PropTypes.string.isRequired, + } + + render() { + const { displayName } = this.props + + const bestPracticesPath = _.find(exampleBestPracticesContext.keys(), path => + new RegExp(`\/${displayName}\/BestPractices\/${displayName}BestPractices\.tsx$`).test(path), + ) + + if (!bestPracticesPath) { + return null + } + + const bestPracticesElement = React.createElement( + exampleBestPracticesContext(bestPracticesPath).default, + ) as any + if (!bestPracticesElement) { + return null + } + + return {bestPracticesElement} + } +} diff --git a/docs/src/components/ComponentDoc/ComponentDoc.tsx b/docs/src/components/ComponentDoc/ComponentDoc.tsx index ff88afd532..f8dc190e48 100644 --- a/docs/src/components/ComponentDoc/ComponentDoc.tsx +++ b/docs/src/components/ComponentDoc/ComponentDoc.tsx @@ -1,17 +1,21 @@ import * as React from 'react' import { RouteComponentProps, withRouter } from 'react-router-dom' -import { Flex, Header, Icon, Dropdown, Text, Grid } from '@stardust-ui/react' +import { Flex, Header, Icon, Dropdown, Text, Grid, Menu, Box } from '@stardust-ui/react' -import { scrollToAnchor, examplePathToHash, getFormattedHash } from 'docs/src/utils' +import { getFormattedHash } from 'docs/src/utils' import ComponentDocLinks from './ComponentDocLinks' import ComponentDocSee from './ComponentDocSee' -import ComponentExamples from './ComponentExamples' +import { ComponentExamples } from './ComponentExamples' +import { ComponentUsage } from './ComponentUsage' import ComponentProps from './ComponentProps' -import ComponentAccessibility from './ComponentDocAccessibility' +import { ComponentDocAccessibility } from './ComponentDocAccessibility' import { ThemeContext } from 'docs/src/context/ThemeContext' import ExampleContext from 'docs/src/context/ExampleContext' import ComponentPlayground from 'docs/src/components/ComponentPlayground/ComponentPlayground' import { ComponentInfo } from 'docs/src/types' +import ComponentBestPractices from './ComponentBestPractices' +import { tabListBehavior } from 'src/lib/accessibility' +import * as _ from 'lodash' const exampleEndStyle: React.CSSProperties = { textAlign: 'center', @@ -21,22 +25,51 @@ const exampleEndStyle: React.CSSProperties = { type ComponentDocProps = { info: ComponentInfo + tabs: string[] } & RouteComponentProps<{}> class ComponentDoc extends React.Component { state: any = {} + tabRegex = new RegExp(/[^\/]*$/) + + getTabIndexOrRedirectToDefault(tab: string) { + const lowercaseTabs = _.map(this.props.tabs, tab => tab.toLowerCase()) + const index = lowercaseTabs.indexOf(tab) + if (index === -1) { + const { history, location } = this.props + const at = location.pathname + const newLocation = at.replace(this.tabRegex, 'definition') + history.replace(newLocation) + return 0 + } + return index + } + + getCurrentTabTitle() { + return this.props.tabs[this.state.currentTabIndex] + } + componentWillMount() { const { history, location } = this.props + const tab = location.pathname.match(this.tabRegex)[0] + const tabIndex = this.getTabIndexOrRedirectToDefault(tab) + this.setState({ currentTabIndex: tabIndex }) if (location.hash) { const activePath = getFormattedHash(location.hash) history.replace(`${location.pathname}#${activePath}`) this.setState({ activePath }) + if (this.props.tabs[tabIndex] === 'Props') { + this.setState({ defaultPropComponent: activePath }) + } } } - componentWillReceiveProps({ info }) { + componentWillReceiveProps({ info, location }) { + const tab = location.pathname.match(this.tabRegex)[0] + this.setState({ currentTabIndex: this.getTabIndexOrRedirectToDefault(tab) }) + if (info.displayName !== this.props.info.displayName) { this.setState({ activePath: undefined }) } @@ -48,6 +81,7 @@ class ComponentDoc extends React.Component { handleExamplesRef = examplesRef => this.setState({ examplesRef }) + /* TODO: bring back the right floating menu handleSidebarItemClick = (e, { examplePath }) => { const { history, location } = this.props const activePath = examplePathToHash(examplePath) @@ -56,6 +90,22 @@ class ComponentDoc extends React.Component { // set active hash path this.setState({ activePath }, scrollToAnchor) } + */ + + handleTabClick = (e, props) => { + const newIndex = props.index + const { history, location } = this.props + const at = location.pathname + const newLocation = at.replace(this.tabRegex, this.props.tabs[newIndex].toLowerCase()) + + history.replace(newLocation) + this.setState({ currentTabIndex: newIndex }) + } + + onPropComponentSelected = (e, props) => { + const { history, location } = this.props + history.replace(`${location.pathname}#${props.value}`) + } render() { const getA11ySelectionMessage = { @@ -124,33 +174,74 @@ class ComponentDoc extends React.Component { /> - - + - - + {this.getCurrentTabTitle() === 'Accessibility' && } + + {this.getCurrentTabTitle() === 'Props' && ( + + )} - -
- + + + + - - +
+ +
+ + + +
+
+ + + )} -
- This is the bottom + {this.getCurrentTabTitle() === 'Usage' && ( + +
+ + +
-
- - {/* TODO: bring back the right floating menu + {/* TODO: bring back the right floating menu { /> */} - + + )} + +
+ This is the bottom +
) } diff --git a/docs/src/components/ComponentDoc/ComponentDocAccessibility.tsx b/docs/src/components/ComponentDoc/ComponentDocAccessibility.tsx index 7618d48965..99beca6bf9 100644 --- a/docs/src/components/ComponentDoc/ComponentDocAccessibility.tsx +++ b/docs/src/components/ComponentDoc/ComponentDocAccessibility.tsx @@ -1,21 +1,37 @@ import * as React from 'react' import * as _ from 'lodash' -import { Flex, Loader, Text, Accordion } from '@stardust-ui/react' +import { Flex, Loader, Text, Provider } from '@stardust-ui/react' const InlineMarkdown = React.lazy(() => import('./InlineMarkdown')) const behaviorMenu = require('docs/src/behaviorMenu') -const ComponentDocAccessibility = ({ info }) => { - const description = _.get(_.find(info.docblock.tags, { title: 'accessibility' }), 'description') +export function containsAccessibility(info) { + const stem = getStem(info) + return !!getDescription(info) || !!getBehaviorName(stem) +} + +function getDescription(info) { + return _.get(_.find(info.docblock.tags, { title: 'accessibility' }), 'description') +} + +function getStem(info) { const defaultValue = _.get(_.find(info.props, { name: 'accessibility' }), 'defaultValue') + return defaultValue && defaultValue.split('.').pop() +} - const stem = defaultValue && defaultValue.split('.').pop() +function getBehaviorName(stem) { const filename = stem && `${stem}.ts` - const behaviorName = behaviorMenu.reduce((acc, next) => { + return behaviorMenu.reduce((acc, next) => { return _.find(next.variations, { name: filename }) ? next.displayName : acc }, null) +} + +export const ComponentDocAccessibility = ({ info }) => { + const stem = getStem(info) + const description = getDescription(info) + const behaviorName = getBehaviorName(stem) if (!behaviorName && !description) return null @@ -57,28 +73,13 @@ const ComponentDocAccessibility = ({ info }) => { ) - const accessPanels = [ - { - key: 'accessibility', - content: { content: accessibilityDetails, styles: { paddingLeft: '14px' } }, - title: { - content: , - as: 'span', - 'aria-level': '2', - styles: { paddingBottom: '0', paddingTop: '0' }, - }, - }, - ] - return ( - <> - - + + {accessibilityDetails} + ) } - -export default ComponentDocAccessibility diff --git a/docs/src/components/ComponentDoc/ComponentExamples.tsx b/docs/src/components/ComponentDoc/ComponentExamples.tsx index c8aa13ed32..900e2b7e1e 100644 --- a/docs/src/components/ComponentDoc/ComponentExamples.tsx +++ b/docs/src/components/ComponentDoc/ComponentExamples.tsx @@ -12,7 +12,24 @@ interface ComponentExamplesProps { displayName: string } -export default class ComponentExamples extends React.Component { +function getExamplesElement(displayName: string) { + // rule #1 + const indexPath = _.find(exampleIndexContext.keys(), path => + new RegExp(`\/${displayName}\/index\.tsx$`).test(path), + ) + if (!indexPath) { + return null + } + + const ExamplesElement = React.createElement(exampleIndexContext(indexPath).default) as any + if (!ExamplesElement) { + return null + } + + return ExamplesElement +} + +export class ComponentExamples extends React.Component { static propTypes = { displayName: PropTypes.string.isRequired, } @@ -23,29 +40,21 @@ export default class ComponentExamples extends React.Component { const { displayName } = this.props - // rule #1 - const indexPath = _.find(exampleIndexContext.keys(), path => - new RegExp(`\/${displayName}\/index\.tsx$`).test(path), - ) - if (!indexPath) { - return null - } - - const ExamplesElement = React.createElement(exampleIndexContext(indexPath).default) as any + const ExamplesElement = getExamplesElement(displayName) if (!ExamplesElement) { return null } - // rules #2 and #3 + // rules #3 and #4 const missingPaths = this.getMissingExamplePaths(displayName, exampleSourcesContext.keys()) return missingPaths && missingPaths.length ? (
diff --git a/docs/src/components/ComponentDoc/ComponentProps/ComponentProps.tsx b/docs/src/components/ComponentDoc/ComponentProps/ComponentProps.tsx index da59ef9873..9279eaf686 100644 --- a/docs/src/components/ComponentDoc/ComponentProps/ComponentProps.tsx +++ b/docs/src/components/ComponentDoc/ComponentProps/ComponentProps.tsx @@ -6,7 +6,7 @@ import { getComponentGroup } from 'docs/src/utils' import ComponentTableProps from '../ComponentPropsTable' import ComponentPropsComponents from './ComponentPropsComponents' import ComponentPropsDescription from './ComponentPropsDescription' -import { ICSSInJSStyle, Flex, Checkbox } from '@stardust-ui/react' +import { ICSSInJSStyle, Flex } from '@stardust-ui/react' const propsContainerStyle: ICSSInJSStyle = { overflowX: 'auto' } @@ -14,12 +14,17 @@ export default class ComponentProps extends React.Component { static propTypes = { displayName: PropTypes.string.isRequired, props: PropTypes.arrayOf(PropTypes.object).isRequired, + defaultComponentProp: PropTypes.string, + onPropComponentSelected: PropTypes.func, } componentWillMount() { - const { displayName } = this.props + const { displayName, defaultComponentProp } = this.props - this.setState({ componentGroup: getComponentGroup(displayName) }) + this.setState({ + componentGroup: getComponentGroup(displayName), + activeDisplayName: defaultComponentProp || displayName, + }) } componentWillReceiveProps({ displayName: next }) { @@ -33,15 +38,9 @@ export default class ComponentProps extends React.Component { } } - handleComponentClick = (e, { name }) => { - this.setState({ activeDisplayName: name }) - } - - handleToggle = () => { - const { displayName } = this.props - const { activeDisplayName } = this.state - - this.setState({ activeDisplayName: activeDisplayName ? false : displayName }) + handleSelectedChange = (e, props) => { + this.setState({ activeDisplayName: props.value }) + _.invoke(this.props, 'onPropComponentSelected', e, props) } render() { @@ -55,11 +54,10 @@ export default class ComponentProps extends React.Component { - diff --git a/docs/src/components/ComponentDoc/ComponentProps/ComponentPropsComponents.tsx b/docs/src/components/ComponentDoc/ComponentProps/ComponentPropsComponents.tsx index c019f1c94f..4f228f8104 100644 --- a/docs/src/components/ComponentDoc/ComponentProps/ComponentPropsComponents.tsx +++ b/docs/src/components/ComponentDoc/ComponentProps/ComponentPropsComponents.tsx @@ -1,36 +1,30 @@ import * as _ from 'lodash' import * as PropTypes from 'prop-types' import * as React from 'react' -import { Menu, tabListBehavior } from '@stardust-ui/react' +import { Dropdown, Header, Flex } from '@stardust-ui/react' const ComponentPropsComponents: any = ({ activeDisplayName, displayNames, - onItemClick, + onSelectedChange, parentDisplayName, }) => { if (displayNames.length < 2) return null - const items: Object[] = _.map(displayNames, displayName => ({ - key: displayName, - active: activeDisplayName === displayName, - content: - displayName === parentDisplayName - ? displayName - : displayName.replace(parentDisplayName, `${parentDisplayName}.`), - name: displayName, - onClick: onItemClick, - styles: { paddingTop: '0px' }, - })) - + const items: Object[] = _.map(displayNames, displayName => + displayName === parentDisplayName + ? displayName + : displayName.replace(parentDisplayName, `${parentDisplayName}`), + ) return ( - + +
Component:
+ +
) } diff --git a/docs/src/components/ComponentDoc/ComponentUsage.tsx b/docs/src/components/ComponentDoc/ComponentUsage.tsx new file mode 100755 index 0000000000..864a6b069b --- /dev/null +++ b/docs/src/components/ComponentDoc/ComponentUsage.tsx @@ -0,0 +1,45 @@ +import * as PropTypes from 'prop-types' +import * as React from 'react' +import * as _ from 'lodash' + +import { usageIndexContext } from 'docs/src/utils' + +interface ComponentUsageProps { + displayName: string +} + +export function containsUsage(displayName: string) { + return !!getUsageElement(displayName) +} + +function getUsageElement(displayName: string) { + const indexPath = _.find(usageIndexContext.keys(), path => + new RegExp(`\/${displayName}\/Usage\/index\.tsx$`).test(path), + ) + if (!indexPath) { + return null + } + + const UsageElement = React.createElement(usageIndexContext(indexPath).default) as any + if (!UsageElement) { + return null + } + + return UsageElement +} + +export class ComponentUsage extends React.Component { + static propTypes = { + displayName: PropTypes.string.isRequired, + } + + render() { + const { displayName } = this.props + const UsageElement = getUsageElement(displayName) + if (!UsageElement) { + return null + } + + return UsageElement + } +} diff --git a/docs/src/components/DocsRoot.tsx b/docs/src/components/DocsRoot.tsx index 7bf1f82820..d0e1097eab 100644 --- a/docs/src/components/DocsRoot.tsx +++ b/docs/src/components/DocsRoot.tsx @@ -5,7 +5,8 @@ import * as React from 'react' import ComponentDoc from '../components/ComponentDoc' import PageNotFound from '../views/PageNotFound' import componentInfoContext from '../utils/componentInfoContext' -import DocsBehaviorRoot from './DocsBehaviorRoot' +import { containsUsage } from './ComponentDoc/ComponentUsage' +import { containsAccessibility } from './ComponentDoc/ComponentDocAccessibility' class DocsRoot extends React.Component { static propTypes = { @@ -13,22 +14,39 @@ class DocsRoot extends React.Component { match: PropTypes.shape({ params: PropTypes.shape({ name: PropTypes.string.isRequired, - type: PropTypes.string.isRequired, + tab: PropTypes.string.isRequired, }), }), } state = {} + getNonEmptyTabs(info) { + const tabs = ['Definition'] + + if (containsUsage(info.displayName)) { + tabs.push('Usage') + } + + tabs.push('Props') + + if (containsAccessibility(info)) { + tabs.push('Accessibility') + } + + return tabs + } + render() { const { match } = this.props const displayName = _.startCase(match.params.name).replace(/ /g, '') if (match.params.type === 'behaviors') { - return + return null } const info = componentInfoContext.byDisplayName[displayName] + const tabs = this.getNonEmptyTabs(info) - if (info) return + if (info) return return } diff --git a/docs/src/components/Sidebar/Sidebar.tsx b/docs/src/components/Sidebar/Sidebar.tsx index ffd0b9ebfc..5cde4d39d9 100644 --- a/docs/src/components/Sidebar/Sidebar.tsx +++ b/docs/src/components/Sidebar/Sidebar.tsx @@ -51,8 +51,16 @@ class Sidebar extends React.Component { } findActiveCategoryIndex = (at: string, sections: ShorthandValue[]): number => { + let newAt = at + if (at.startsWith('/components')) { + newAt = newAt.replace(/[^\/]*$/, '') + } + if (newAt[newAt.length - 1] === '/') { + newAt = newAt.substr(0, newAt.length - 1) + } + return _.findIndex(sections, (section: ShorthandValue) => { - return _.find((section as any).items, item => item.title.to === at) + return _.find((section as any).items, item => item.title.to.startsWith(newAt)) }) } diff --git a/docs/src/examples/components/Accordion/BestPractices/index.tsx b/docs/src/examples/components/Accordion/BestPractices/index.tsx deleted file mode 100644 index 9a93773334..0000000000 --- a/docs/src/examples/components/Accordion/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import AccordionBestPractices from './AccordionBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Accordion/Usage/index.tsx b/docs/src/examples/components/Accordion/Usage/index.tsx index 480e46eccc..263c86033a 100644 --- a/docs/src/examples/components/Accordion/Usage/index.tsx +++ b/docs/src/examples/components/Accordion/Usage/index.tsx @@ -3,7 +3,7 @@ import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const Usage = () => ( - + ( <> - - ) diff --git a/docs/src/examples/components/Alert/BestPractices/index.tsx b/docs/src/examples/components/Alert/BestPractices/index.tsx deleted file mode 100644 index 9509d8c786..0000000000 --- a/docs/src/examples/components/Alert/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import AlertBestPractices from './AlertBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Alert/index.tsx b/docs/src/examples/components/Alert/index.tsx index 0ade5705a1..c184793bbf 100644 --- a/docs/src/examples/components/Alert/index.tsx +++ b/docs/src/examples/components/Alert/index.tsx @@ -3,11 +3,9 @@ import * as React from 'react' import Rtl from './Rtl' import Types from './Types' import Variations from './Variations' -import BestPractices from './BestPractices' const AlertExamples = () => ( <> - diff --git a/docs/src/examples/components/Avatar/Usage/index.tsx b/docs/src/examples/components/Avatar/Usage/index.tsx index 4fce4a8bfc..ba2698a499 100644 --- a/docs/src/examples/components/Avatar/Usage/index.tsx +++ b/docs/src/examples/components/Avatar/Usage/index.tsx @@ -3,7 +3,7 @@ import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const Usage = () => ( - + ( <> - ) diff --git a/docs/src/examples/components/Button/BestPractices/index.tsx b/docs/src/examples/components/Button/BestPractices/index.tsx deleted file mode 100644 index bfa0bef58a..0000000000 --- a/docs/src/examples/components/Button/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import ButtonBestPractices from './ButtonBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Button/Types/index.tsx b/docs/src/examples/components/Button/Types/index.tsx index b2fe655fa6..29861bfc8f 100644 --- a/docs/src/examples/components/Button/Types/index.tsx +++ b/docs/src/examples/components/Button/Types/index.tsx @@ -24,11 +24,6 @@ const Types = () => ( description="A button can be formatted differently if it indicate that it contains only an icon." examplePath="components/Button/Types/ButtonExampleIconOnly" /> - ) diff --git a/docs/src/examples/components/Button/Types/ButtonExampleContentAndIcon.shorthand.steps.ts b/docs/src/examples/components/Button/Usage/ButtonExampleContentAndIcon.shorthand.steps.ts similarity index 100% rename from docs/src/examples/components/Button/Types/ButtonExampleContentAndIcon.shorthand.steps.ts rename to docs/src/examples/components/Button/Usage/ButtonExampleContentAndIcon.shorthand.steps.ts diff --git a/docs/src/examples/components/Button/Types/ButtonExampleContentAndIcon.shorthand.tsx b/docs/src/examples/components/Button/Usage/ButtonExampleContentAndIcon.shorthand.tsx similarity index 100% rename from docs/src/examples/components/Button/Types/ButtonExampleContentAndIcon.shorthand.tsx rename to docs/src/examples/components/Button/Usage/ButtonExampleContentAndIcon.shorthand.tsx diff --git a/docs/src/examples/components/Button/Types/ButtonExampleContentAndIcon.tsx b/docs/src/examples/components/Button/Usage/ButtonExampleContentAndIcon.tsx similarity index 100% rename from docs/src/examples/components/Button/Types/ButtonExampleContentAndIcon.tsx rename to docs/src/examples/components/Button/Usage/ButtonExampleContentAndIcon.tsx diff --git a/docs/src/examples/components/Button/Usage/index.tsx b/docs/src/examples/components/Button/Usage/index.tsx index 05ad093ecc..1ad904f416 100644 --- a/docs/src/examples/components/Button/Usage/index.tsx +++ b/docs/src/examples/components/Button/Usage/index.tsx @@ -4,7 +4,12 @@ import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const Usage = () => ( - + + ( <> - - diff --git a/docs/src/examples/components/Dialog/BestPractices/index.tsx b/docs/src/examples/components/Dialog/BestPractices/index.tsx deleted file mode 100644 index c419eb27ce..0000000000 --- a/docs/src/examples/components/Dialog/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import DialogBestPractices from './DialogBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Dialog/Usage/index.tsx b/docs/src/examples/components/Dialog/Usage/index.tsx index 02343499ab..c9a96b7a16 100644 --- a/docs/src/examples/components/Dialog/Usage/index.tsx +++ b/docs/src/examples/components/Dialog/Usage/index.tsx @@ -4,7 +4,7 @@ import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const DialogUsageExamples = () => ( - + ( <> - - ) diff --git a/docs/src/examples/components/Dropdown/BestPractices/index.tsx b/docs/src/examples/components/Dropdown/BestPractices/index.tsx deleted file mode 100644 index 3079a39bfb..0000000000 --- a/docs/src/examples/components/Dropdown/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import DropdownBestPractices from './DropdownBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Dropdown/Usage/index.tsx b/docs/src/examples/components/Dropdown/Usage/index.tsx index 1f36099ebc..d5f18fd3f6 100644 --- a/docs/src/examples/components/Dropdown/Usage/index.tsx +++ b/docs/src/examples/components/Dropdown/Usage/index.tsx @@ -3,7 +3,7 @@ import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const Usage = () => ( - + ( <> - - diff --git a/docs/src/examples/components/Embed/Usage/index.tsx b/docs/src/examples/components/Embed/Usage/index.tsx index d5060e1e49..0a91cf2988 100644 --- a/docs/src/examples/components/Embed/Usage/index.tsx +++ b/docs/src/examples/components/Embed/Usage/index.tsx @@ -4,7 +4,7 @@ import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const Usage = () => ( - + ( <> - ) diff --git a/docs/src/examples/components/Form/BestPractices/index.tsx b/docs/src/examples/components/Form/BestPractices/index.tsx deleted file mode 100644 index b6e4a661b6..0000000000 --- a/docs/src/examples/components/Form/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import FormBestPractices from './FormBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Form/index.tsx b/docs/src/examples/components/Form/index.tsx index 3eaacdad08..cd13e449c0 100644 --- a/docs/src/examples/components/Form/index.tsx +++ b/docs/src/examples/components/Form/index.tsx @@ -1,12 +1,10 @@ import * as React from 'react' -import BestPractices from './BestPractices' import Rtl from './Rtl' import Types from './Types' const FormExamples = () => (
-
diff --git a/docs/src/examples/components/Grid/BestPractices/index.tsx b/docs/src/examples/components/Grid/BestPractices/index.tsx deleted file mode 100644 index 9165aea0de..0000000000 --- a/docs/src/examples/components/Grid/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import GridBestPractices from './GridBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Grid/index.tsx b/docs/src/examples/components/Grid/index.tsx index 0f039d3bdc..ffb33f0460 100644 --- a/docs/src/examples/components/Grid/index.tsx +++ b/docs/src/examples/components/Grid/index.tsx @@ -2,7 +2,6 @@ import * as React from 'react' import { Alert } from '@stardust-ui/react' import { Link } from 'react-router-dom' -import BestPractices from './BestPractices' import Rtl from './Rtl' import Types from './Types' import Variations from './Variations' @@ -16,7 +15,6 @@ const GridExamples = () => (

- diff --git a/docs/src/examples/components/Icon/BestPractices/index.tsx b/docs/src/examples/components/Icon/BestPractices/index.tsx deleted file mode 100644 index 8b41354c77..0000000000 --- a/docs/src/examples/components/Icon/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import IconBestPractices from './IconBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Icon/Usage/index.tsx b/docs/src/examples/components/Icon/Usage/index.tsx index edce4e6461..318e8a6fa8 100644 --- a/docs/src/examples/components/Icon/Usage/index.tsx +++ b/docs/src/examples/components/Icon/Usage/index.tsx @@ -3,7 +3,7 @@ import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const Usage = () => ( - + (
- -
diff --git a/docs/src/examples/components/Input/BestPractices/index.tsx b/docs/src/examples/components/Input/BestPractices/index.tsx deleted file mode 100644 index 7a793b66ef..0000000000 --- a/docs/src/examples/components/Input/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import InputBestPractices from './InputBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Input/index.tsx b/docs/src/examples/components/Input/index.tsx index 1fa6887169..8204c345b0 100644 --- a/docs/src/examples/components/Input/index.tsx +++ b/docs/src/examples/components/Input/index.tsx @@ -1,13 +1,11 @@ import * as React from 'react' -import BestPractices from './BestPractices' import Rtl from './Rtl' import Types from './Types' import Variations from './Variations' const InputExamples = () => (
- diff --git a/docs/src/examples/components/Loader/Usage/index.tsx b/docs/src/examples/components/Loader/Usage/index.tsx index ee9faf1d7a..66e81cd0b0 100644 --- a/docs/src/examples/components/Loader/Usage/index.tsx +++ b/docs/src/examples/components/Loader/Usage/index.tsx @@ -4,7 +4,7 @@ import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const LoaderUsageExamples = () => ( - + ( <> - diff --git a/docs/src/examples/components/Menu/BestPractices/index.tsx b/docs/src/examples/components/Menu/BestPractices/index.tsx deleted file mode 100644 index 5b7156b301..0000000000 --- a/docs/src/examples/components/Menu/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import MenuBestPractices from './MenuBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Menu/Usages/MenuExampleTabList.shorthand.tsx b/docs/src/examples/components/Menu/Usage/MenuExampleTabList.shorthand.tsx similarity index 100% rename from docs/src/examples/components/Menu/Usages/MenuExampleTabList.shorthand.tsx rename to docs/src/examples/components/Menu/Usage/MenuExampleTabList.shorthand.tsx diff --git a/docs/src/examples/components/Menu/Usages/MenuExampleToolbar.shorthand.steps.ts b/docs/src/examples/components/Menu/Usage/MenuExampleToolbar.shorthand.steps.ts similarity index 100% rename from docs/src/examples/components/Menu/Usages/MenuExampleToolbar.shorthand.steps.ts rename to docs/src/examples/components/Menu/Usage/MenuExampleToolbar.shorthand.steps.ts diff --git a/docs/src/examples/components/Menu/Usages/MenuExampleToolbar.shorthand.tsx b/docs/src/examples/components/Menu/Usage/MenuExampleToolbar.shorthand.tsx similarity index 100% rename from docs/src/examples/components/Menu/Usages/MenuExampleToolbar.shorthand.tsx rename to docs/src/examples/components/Menu/Usage/MenuExampleToolbar.shorthand.tsx diff --git a/docs/src/examples/components/Menu/Usages/MenuExampleWithSubmenu.shorthand.steps.ts b/docs/src/examples/components/Menu/Usage/MenuExampleWithSubmenu.shorthand.steps.ts similarity index 100% rename from docs/src/examples/components/Menu/Usages/MenuExampleWithSubmenu.shorthand.steps.ts rename to docs/src/examples/components/Menu/Usage/MenuExampleWithSubmenu.shorthand.steps.ts diff --git a/docs/src/examples/components/Menu/Usages/MenuExampleWithSubmenu.shorthand.tsx b/docs/src/examples/components/Menu/Usage/MenuExampleWithSubmenu.shorthand.tsx similarity index 100% rename from docs/src/examples/components/Menu/Usages/MenuExampleWithSubmenu.shorthand.tsx rename to docs/src/examples/components/Menu/Usage/MenuExampleWithSubmenu.shorthand.tsx diff --git a/docs/src/examples/components/Menu/Usages/MenuExampleWithSubmenuControlled.shorthand.tsx b/docs/src/examples/components/Menu/Usage/MenuExampleWithSubmenuControlled.shorthand.tsx similarity index 100% rename from docs/src/examples/components/Menu/Usages/MenuExampleWithSubmenuControlled.shorthand.tsx rename to docs/src/examples/components/Menu/Usage/MenuExampleWithSubmenuControlled.shorthand.tsx diff --git a/docs/src/examples/components/Menu/Usages/MenuExampleWithTooltip.shorthand.steps.ts b/docs/src/examples/components/Menu/Usage/MenuExampleWithTooltip.shorthand.steps.ts similarity index 100% rename from docs/src/examples/components/Menu/Usages/MenuExampleWithTooltip.shorthand.steps.ts rename to docs/src/examples/components/Menu/Usage/MenuExampleWithTooltip.shorthand.steps.ts diff --git a/docs/src/examples/components/Menu/Usages/MenuExampleWithTooltip.shorthand.tsx b/docs/src/examples/components/Menu/Usage/MenuExampleWithTooltip.shorthand.tsx similarity index 100% rename from docs/src/examples/components/Menu/Usages/MenuExampleWithTooltip.shorthand.tsx rename to docs/src/examples/components/Menu/Usage/MenuExampleWithTooltip.shorthand.tsx diff --git a/docs/src/examples/components/Menu/Usages/index.tsx b/docs/src/examples/components/Menu/Usage/index.tsx similarity index 74% rename from docs/src/examples/components/Menu/Usages/index.tsx rename to docs/src/examples/components/Menu/Usage/index.tsx index 24587dda21..93d1a3ea52 100644 --- a/docs/src/examples/components/Menu/Usages/index.tsx +++ b/docs/src/examples/components/Menu/Usage/index.tsx @@ -3,27 +3,27 @@ import { Link } from 'react-router-dom' import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' -const Usages = () => ( - +const Usage = () => ( + ( tooltip } - examplePath="components/Menu/Usages/MenuExampleWithTooltip" + examplePath="components/Menu/Usage/MenuExampleWithTooltip" /> ) -export default Usages +export default Usage diff --git a/docs/src/examples/components/Menu/index.tsx b/docs/src/examples/components/Menu/index.tsx index 6881ba1aea..9a90ade790 100644 --- a/docs/src/examples/components/Menu/index.tsx +++ b/docs/src/examples/components/Menu/index.tsx @@ -1,21 +1,17 @@ import * as React from 'react' -import BestPractices from './BestPractices' import Rtl from './Rtl' import Types from './Types' import Slots from './Slots' import States from './States' import Variations from './Variations' -import Usages from './Usages' const MenuExamples = () => (
- -
) diff --git a/docs/src/examples/components/MenuButton/Usage/index.tsx b/docs/src/examples/components/MenuButton/Usage/index.tsx index 21d5b8687d..5cc2a8e24f 100644 --- a/docs/src/examples/components/MenuButton/Usage/index.tsx +++ b/docs/src/examples/components/MenuButton/Usage/index.tsx @@ -4,7 +4,7 @@ import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const Usage = () => ( - + ( <> - diff --git a/docs/src/examples/components/Popup/BestPractices/index.tsx b/docs/src/examples/components/Popup/BestPractices/index.tsx deleted file mode 100644 index 5671cbc025..0000000000 --- a/docs/src/examples/components/Popup/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import PopupBestPractices from './PopupBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Popup/Usage/index.tsx b/docs/src/examples/components/Popup/Usage/index.tsx index bc43350695..3ccb7950cb 100644 --- a/docs/src/examples/components/Popup/Usage/index.tsx +++ b/docs/src/examples/components/Popup/Usage/index.tsx @@ -4,7 +4,7 @@ import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const Usage = () => ( - + ( <> - - ) diff --git a/docs/src/examples/components/Provider/Usage/index.tsx b/docs/src/examples/components/Provider/Usage/index.tsx index a51dcfaf5c..1822823f8a 100644 --- a/docs/src/examples/components/Provider/Usage/index.tsx +++ b/docs/src/examples/components/Provider/Usage/index.tsx @@ -4,7 +4,7 @@ import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const Usage = () => ( - + ( <> - ) diff --git a/docs/src/examples/components/Reaction/BestPractices/index.tsx b/docs/src/examples/components/Reaction/BestPractices/index.tsx deleted file mode 100644 index 1e29ee3aab..0000000000 --- a/docs/src/examples/components/Reaction/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import ReactionBestPractices from './ReactionBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Reaction/index.tsx b/docs/src/examples/components/Reaction/index.tsx index aad23dab16..9943f19e0d 100644 --- a/docs/src/examples/components/Reaction/index.tsx +++ b/docs/src/examples/components/Reaction/index.tsx @@ -1,12 +1,10 @@ import * as React from 'react' -import BestPractices from './BestPractices' import Rtl from './Rtl' import Types from './Types' const ReactionExamples = () => ( <> - diff --git a/docs/src/examples/components/Slider/BestPractices/index.tsx b/docs/src/examples/components/Slider/BestPractices/index.tsx deleted file mode 100644 index 3411575bc1..0000000000 --- a/docs/src/examples/components/Slider/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import SliderBestPractices from './SliderBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Slider/Usage/index.tsx b/docs/src/examples/components/Slider/Usage/index.tsx index 75df8a8636..0455309146 100644 --- a/docs/src/examples/components/Slider/Usage/index.tsx +++ b/docs/src/examples/components/Slider/Usage/index.tsx @@ -3,7 +3,7 @@ import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const Usage = () => ( - + ( <> - - ) diff --git a/docs/src/examples/components/Status/BestPractices/index.tsx b/docs/src/examples/components/Status/BestPractices/index.tsx deleted file mode 100644 index 5e31ba6c85..0000000000 --- a/docs/src/examples/components/Status/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import StatusBestPractices from './StatusBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Status/index.tsx b/docs/src/examples/components/Status/index.tsx index 40e76dc865..6178c34bb5 100644 --- a/docs/src/examples/components/Status/index.tsx +++ b/docs/src/examples/components/Status/index.tsx @@ -1,12 +1,10 @@ import * as React from 'react' -import BestPractices from './BestPractices' import Types from './Types' import Variations from './Variations' const StatusExamples = () => (
-
diff --git a/docs/src/examples/components/Text/BestPractices/index.tsx b/docs/src/examples/components/Text/BestPractices/index.tsx deleted file mode 100644 index a1a75a92f2..0000000000 --- a/docs/src/examples/components/Text/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import TextBestPractices from './TextBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Text/index.tsx b/docs/src/examples/components/Text/index.tsx index 978a2f0660..7640a28062 100644 --- a/docs/src/examples/components/Text/index.tsx +++ b/docs/src/examples/components/Text/index.tsx @@ -1,6 +1,5 @@ import * as React from 'react' -import BestPractices from './BestPractices' import Rtl from './Rtl' import States from './States' import Types from './Types' @@ -8,7 +7,6 @@ import Variations from './Variations' const TextExamples = () => ( <> - diff --git a/docs/src/examples/components/Toolbar/Usage/index.tsx b/docs/src/examples/components/Toolbar/Usage/index.tsx index cd67449aaf..74ceb4401c 100644 --- a/docs/src/examples/components/Toolbar/Usage/index.tsx +++ b/docs/src/examples/components/Toolbar/Usage/index.tsx @@ -4,7 +4,7 @@ import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const Usage = () => ( - + ( <> - ) diff --git a/docs/src/examples/components/Tooltip/BestPractices/index.tsx b/docs/src/examples/components/Tooltip/BestPractices/index.tsx deleted file mode 100644 index b502484028..0000000000 --- a/docs/src/examples/components/Tooltip/BestPractices/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import * as React from 'react' - -import TooltipBestPractices from '././TooltipBestPractices' -import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' - -const BestPractices = () => ( - - - -) - -export default BestPractices diff --git a/docs/src/examples/components/Tooltip/Usage/index.tsx b/docs/src/examples/components/Tooltip/Usage/index.tsx index 93c4e114b6..620f76a281 100644 --- a/docs/src/examples/components/Tooltip/Usage/index.tsx +++ b/docs/src/examples/components/Tooltip/Usage/index.tsx @@ -4,7 +4,7 @@ import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' const Usage = () => ( - + ( <> - - ) diff --git a/docs/src/routes.tsx b/docs/src/routes.tsx index 3573e5c96b..f3fcfc5480 100644 --- a/docs/src/routes.tsx +++ b/docs/src/routes.tsx @@ -1,9 +1,10 @@ import * as React from 'react' -import { BrowserRouter, Route, Switch } from 'react-router-dom' +import { BrowserRouter, Route, Switch, Redirect } from 'react-router-dom' import ExternalExampleLayout from './components/ExternalExampleLayout' import DocsLayout from './components/DocsLayout' import DocsRoot from './components/DocsRoot' +import DocsBehaviorRoot from './components/DocsBehaviorRoot' import MarkdownPage from 'docs/src/components/MarkdownPage' import * as Composition from './pages/Composition.mdx' @@ -47,7 +48,13 @@ const Routes = () => ( - + + } + /> + diff --git a/docs/src/utils/exampleContexts.ts b/docs/src/utils/exampleContexts.ts index 4121e1e141..04d0572594 100644 --- a/docs/src/utils/exampleContexts.ts +++ b/docs/src/utils/exampleContexts.ts @@ -3,6 +3,20 @@ */ export const exampleIndexContext = require.context('docs/src/examples/', true, /index.tsx$/) +/** + * The Webpack Context for doc site usage groups. + */ +export const usageIndexContext = require.context('docs/src/examples', true, /Usage\/index.tsx$/) + +/** + * The Webpack Context for doc site example groups. + */ +export const exampleBestPracticesContext = require.context( + 'docs/src/examples/', + true, + /BestPractices.tsx$/, +) + /** * The Webpack Context for component playgrounds. */ diff --git a/docs/src/utils/index.tsx b/docs/src/utils/index.tsx index 8ddd177e53..f524569d5c 100644 --- a/docs/src/utils/index.tsx +++ b/docs/src/utils/index.tsx @@ -1,6 +1,8 @@ export { default as componentInfoContext } from './componentInfoContext' export { exampleIndexContext, + usageIndexContext, + exampleBestPracticesContext, examplePlaygroundContext, exampleSourcesContext, } from './exampleContexts'