diff --git a/CHANGELOG.md b/CHANGELOG.md index fccc8cbfb0..784d49c8a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Documentation - Remove Usage tab @lucivpav ([#1948](https://github.com/stardust-ui/react/pull/1948)) +- Put props on a single page, fix props links @lucivpav ([#1892](https://github.com/stardust-ui/react/pull/1892)) ### Documentation - Remove cancel button in a `Dialog` example with a close action @lucivpav ([#1949](https://github.com/stardust-ui/react/pull/1949)) diff --git a/docs/src/components/ComponentDoc/ComponentDoc.tsx b/docs/src/components/ComponentDoc/ComponentDoc.tsx index 59c6d852eb..e8a5529bad 100644 --- a/docs/src/components/ComponentDoc/ComponentDoc.tsx +++ b/docs/src/components/ComponentDoc/ComponentDoc.tsx @@ -30,20 +30,19 @@ type ComponentDocProps = { type ComponentDocState = { activePath: string currentTabIndex: number - defaultPropComponent: string } class ComponentDoc extends React.Component { state = { activePath: '', - defaultPropComponent: '', + propComponent: '', currentTabIndex: 0, } tabRegex = new RegExp(/[^\/]*$/) - getTabIndexOrRedirectToDefault(tab: string) { - const lowercaseTabs = _.map(this.props.tabs, tab => tab.toLowerCase()) + getTabIndexOrRedirectToDefault(tab: string, tabs) { + const lowercaseTabs = _.map(tabs, tab => tab.toLowerCase()) const index = lowercaseTabs.indexOf(tab) if (index === -1) { const { history, location } = this.props @@ -60,24 +59,22 @@ class ComponentDoc extends React.Component } componentWillMount() { - const { history, location } = this.props + const { history, location, tabs } = this.props const tab = location.pathname.match(this.tabRegex)[0] - const tabIndex = this.getTabIndexOrRedirectToDefault(tab) + const tabIndex = this.getTabIndexOrRedirectToDefault(tab, tabs) this.setState({ currentTabIndex: tabIndex }) if (location.hash) { const activePath = getFormattedHash(location.hash) history.replace({ ...history.location, hash: activePath }) this.setState({ activePath }) - if (this.props.tabs[tabIndex] === 'Props') { - this.setState({ defaultPropComponent: activePath }) - } } } - componentWillReceiveProps({ info, location }) { + componentWillReceiveProps({ info, location, tabs }) { const tab = location.pathname.match(this.tabRegex)[0] - this.setState({ currentTabIndex: this.getTabIndexOrRedirectToDefault(tab) }) + const tabIndex = this.getTabIndexOrRedirectToDefault(tab, tabs) + this.setState({ currentTabIndex: tabIndex }) if (info.displayName !== this.props.info.displayName) { this.setState({ activePath: undefined }) @@ -109,11 +106,6 @@ class ComponentDoc extends React.Component this.setState({ currentTabIndex: newIndex }) } - onPropComponentSelected = (e, props) => { - const { history } = this.props - history.push({ ...history.location, hash: props.value }) - } - render() { const getA11ySelectionMessage = { onAdd: item => `${item} has been selected.`, @@ -142,7 +134,7 @@ class ComponentDoc extends React.Component } const { info, tabs } = this.props - const { activePath, currentTabIndex, defaultPropComponent } = this.state + const { activePath, currentTabIndex } = this.state return (
@@ -197,12 +189,7 @@ class ComponentDoc extends React.Component {this.getCurrentTabTitle() === 'Accessibility' && } {this.getCurrentTabTitle() === 'Props' && ( - + )} {this.getCurrentTabTitle() === 'Definition' && ( diff --git a/docs/src/components/ComponentDoc/ComponentProps/ComponentPropCard.tsx b/docs/src/components/ComponentDoc/ComponentProps/ComponentPropCard.tsx new file mode 100644 index 0000000000..930ec03a6e --- /dev/null +++ b/docs/src/components/ComponentDoc/ComponentProps/ComponentPropCard.tsx @@ -0,0 +1,22 @@ +import * as React from 'react' +import ComponentTableProps from '../ComponentPropsTable' +import { Divider, Segment } from '@stardust-ui/react/src' + +export const cardStyle: React.CSSProperties = { + boxShadow: '0 1px 2px rgba(0, 0, 0, 0.2)', +} + +type ComponentPropCardProps = { + name: string + description: string +} + +const ComponentPropCard: React.FC = ({ name, description }) => ( + +
{description}
+ + +
+) + +export default ComponentPropCard diff --git a/docs/src/components/ComponentDoc/ComponentProps/ComponentProps.tsx b/docs/src/components/ComponentDoc/ComponentProps/ComponentProps.tsx index 9279eaf686..7104a827f3 100644 --- a/docs/src/components/ComponentDoc/ComponentProps/ComponentProps.tsx +++ b/docs/src/components/ComponentDoc/ComponentProps/ComponentProps.tsx @@ -2,74 +2,56 @@ import * as _ from 'lodash' import * as PropTypes from 'prop-types' import * as React from 'react' -import { getComponentGroup } from 'docs/src/utils' -import ComponentTableProps from '../ComponentPropsTable' -import ComponentPropsComponents from './ComponentPropsComponents' -import ComponentPropsDescription from './ComponentPropsDescription' -import { ICSSInJSStyle, Flex } from '@stardust-ui/react' - -const propsContainerStyle: ICSSInJSStyle = { overflowX: 'auto' } +import { getComponentGroup, scrollToAnchor } from 'docs/src/utils' +import ComponentPropsOutline from './ComponentPropsOutline' +import { Flex, Header } from '@stardust-ui/react' +import ComponentPropCard from './ComponentPropCard' 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, defaultComponentProp } = this.props + const { displayName } = this.props this.setState({ componentGroup: getComponentGroup(displayName), - activeDisplayName: defaultComponentProp || displayName, }) + scrollToAnchor() } - componentWillReceiveProps({ displayName: next }) { - const current = this.props.displayName - - if (current !== next) { - this.setState({ - activeDisplayName: null, - componentGroup: getComponentGroup(next), - }) - } - } + componentWillReceiveProps(nextProps) { + const { displayName } = nextProps - handleSelectedChange = (e, props) => { - this.setState({ activeDisplayName: props.value }) - _.invoke(this.props, 'onPropComponentSelected', e, props) + this.setState({ + componentGroup: getComponentGroup(displayName), + }) + scrollToAnchor() } render() { - const { displayName } = this.props - const { activeDisplayName, componentGroup } = this.state + const { componentGroup } = this.state const displayNames = _.keys(componentGroup) - const { docblock } = (componentGroup[activeDisplayName] || {}) as any - const description = _.get(docblock, 'description', []) return ( - + - {activeDisplayName && ( - + {_.map(displayNames, displayName => { + const description = _.get(componentGroup, [displayName, 'docblock', 'description'], '') + const showHeader = displayNames.length > 1 + return ( <> - - + {showHeader &&
} + - - )} + ) + })} ) } diff --git a/docs/src/components/ComponentDoc/ComponentProps/ComponentPropsComponents.tsx b/docs/src/components/ComponentDoc/ComponentProps/ComponentPropsComponents.tsx deleted file mode 100644 index 4f228f8104..0000000000 --- a/docs/src/components/ComponentDoc/ComponentProps/ComponentPropsComponents.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import * as _ from 'lodash' -import * as PropTypes from 'prop-types' -import * as React from 'react' -import { Dropdown, Header, Flex } from '@stardust-ui/react' - -const ComponentPropsComponents: any = ({ - activeDisplayName, - displayNames, - onSelectedChange, - parentDisplayName, -}) => { - if (displayNames.length < 2) return null - - const items: Object[] = _.map(displayNames, displayName => - displayName === parentDisplayName - ? displayName - : displayName.replace(parentDisplayName, `${parentDisplayName}`), - ) - return ( - -
Component:
- -
- ) -} - -ComponentPropsComponents.propTypes = { - activeDisplayName: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]), - displayNames: PropTypes.array, - onItemClick: PropTypes.func, - parentDisplayName: PropTypes.string.isRequired, -} - -const areEqualProps = (prevProps, nextProps) => - prevProps.activeDisplayName === nextProps.activeDisplayName && - prevProps.parentDisplayName === nextProps.parentDisplayName - -export default React.memo(ComponentPropsComponents, areEqualProps) diff --git a/docs/src/components/ComponentDoc/ComponentProps/ComponentPropsDescription.tsx b/docs/src/components/ComponentDoc/ComponentProps/ComponentPropsDescription.tsx deleted file mode 100644 index c0b700791c..0000000000 --- a/docs/src/components/ComponentDoc/ComponentProps/ComponentPropsDescription.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import * as PropTypes from 'prop-types' -import * as React from 'react' -import { Divider } from '@stardust-ui/react' - -const descriptionStyle = { - color: '#777', - fontSize: '1.08em', -} - -export default class ComponentPropsDescription extends React.PureComponent { - static propTypes = { - description: PropTypes.string, - } - - render() { - const { description } = this.props - - return ( -
- {description} - -
- ) - } -} diff --git a/docs/src/components/ComponentDoc/ComponentProps/ComponentPropsOutline.tsx b/docs/src/components/ComponentDoc/ComponentProps/ComponentPropsOutline.tsx new file mode 100644 index 0000000000..4ffd7fc9bd --- /dev/null +++ b/docs/src/components/ComponentDoc/ComponentProps/ComponentPropsOutline.tsx @@ -0,0 +1,22 @@ +import * as _ from 'lodash' +import * as React from 'react' +import { link } from 'docs/src/utils/helpers' + +const ComponentPropsOutline: any = (props: ComponentPropsOutlineProps) => { + const { displayNames } = props + if (displayNames.length < 2) return null + + return ( +
    + {_.map(displayNames, item => ( +
  • {link(item, `#${_.kebabCase(item)}`)}
  • + ))} +
+ ) +} + +export interface ComponentPropsOutlineProps { + displayNames: string[] +} + +export default ComponentPropsOutline diff --git a/docs/src/components/ComponentDoc/ComponentPropsTable/ComponentPropsRow.tsx b/docs/src/components/ComponentDoc/ComponentPropsTable/ComponentPropsRow.tsx index 098f1315f6..8ecff0fcd8 100644 --- a/docs/src/components/ComponentDoc/ComponentPropsTable/ComponentPropsRow.tsx +++ b/docs/src/components/ComponentDoc/ComponentPropsTable/ComponentPropsRow.tsx @@ -5,6 +5,7 @@ import { Link } from 'react-router-dom' import { ComponentProp, ComponentPropType } from 'docs/src/types' import componentInfoContext from 'docs/src/utils/componentInfoContext' import ComponentPropName from '../ComponentProp/ComponentPropName' +import { getComponentGroup } from 'docs/src/utils' const InlineMarkdown = React.lazy(() => import('../InlineMarkdown')) @@ -23,11 +24,14 @@ const ComponentPropValue: React.FunctionComponent = props => const kindParam = parameters[1] && parameters[1].name !== 'never' const kindIsVisible = name === 'ShorthandCollection' && kindParam + const showHash = parentInfo.parentDisplayName || _.size(getComponentGroup(componentName)) > 1 + const propsSection = showHash ? `#${_.kebabCase(componentName)}` : '' + return ( {name} {`<`} - {parameters[0].name} + {parameters[0].name} {kindIsVisible && , {parameters[1].name}} {`>`} diff --git a/docs/src/components/ComponentDoc/ComponentPropsTable/ComponentPropsTable.tsx b/docs/src/components/ComponentDoc/ComponentPropsTable/ComponentPropsTable.tsx index 317ba8fb2e..3919d34709 100644 --- a/docs/src/components/ComponentDoc/ComponentPropsTable/ComponentPropsTable.tsx +++ b/docs/src/components/ComponentDoc/ComponentPropsTable/ComponentPropsTable.tsx @@ -7,6 +7,7 @@ import ComponentPropsRow from './ComponentPropsRow' const tableStyles: React.CSSProperties = { textAlign: 'left', borderCollapse: 'collapse', + width: '100%', } type ComponentPropsTable = { diff --git a/docs/src/components/DocsLayout.tsx b/docs/src/components/DocsLayout.tsx index d4c15be002..cd950400f4 100644 --- a/docs/src/components/DocsLayout.tsx +++ b/docs/src/components/DocsLayout.tsx @@ -59,7 +59,10 @@ class DocsLayout extends React.Component { // Anchor links has issues with // https://stackoverflow.com/questions/8108836/make-anchor-links-refer-to-the-current-page-when-using-base document.querySelectorAll('a.anchor-link').forEach(link => { - link.setAttribute('href', `${document.location.href}${link.getAttribute('href')}`) + const value = `${document.location.origin}${document.location.pathname}${link.getAttribute( + 'href', + )}` + link.setAttribute('href', value) }) }