|
| 1 | +import React from 'react'; |
| 2 | +import { Router } from 'director'; |
| 3 | + |
| 4 | +import { Grid, Row, Col, Tree, TreeNode } from 'react-lightning-design-system'; |
| 5 | + |
| 6 | +import ButtonExamples from './ButtonExamples'; |
| 7 | +import ButtonGroupExamples from './ButtonGroupExamples'; |
| 8 | +import DatepickerExamples from './DatepickerExamples'; |
| 9 | +import DropdownButtonExamples from './DropdownButtonExamples'; |
| 10 | +import FormExamples from './FormExamples'; |
| 11 | +import GridExamples from './GridExamples'; |
| 12 | +import IconExamples from './IconExamples'; |
| 13 | +import LookupExamples from './LookupExamples'; |
| 14 | +import ModalExamples from './ModalExamples'; |
| 15 | +import NotificationExamples from './NotificationExamples'; |
| 16 | +import TabsExamples from './TabsExamples'; |
| 17 | +import TreeExamples from './TreeExamples'; |
| 18 | +import BadgeExamples from './BadgeExamples'; |
| 19 | +import BreadCrumbsExamples from './BreadCrumbsExamples'; |
| 20 | +import PopoverExamples from './PopoverExamples'; |
| 21 | +import PageHeaderExamples from './PageHeaderExamples'; |
| 22 | +import MediaObjectExamples from './MediaObjectExamples'; |
| 23 | +import TableExamples from './TableExamples'; |
| 24 | +import SpinnerExamples from './SpinnerExamples'; |
| 25 | +import ToggleExamples from './ToggleExamples'; |
| 26 | +import FileSelectorExamples from './FileSelectorExamples'; |
| 27 | +import CardExamples from './CardExamples'; |
| 28 | + |
| 29 | +const SECTIONS = { |
| 30 | + table: { label: 'Data Table', klass: TableExamples, src: 'TableExamples' }, |
| 31 | + badge: { label: 'Badge', klass: BadgeExamples, src: 'BadgeExamples' }, |
| 32 | + breadcrumbs: { label: 'Breadcrumbs', klass: BreadCrumbsExamples, src: 'BreadCrumbsExamples' }, |
| 33 | + button: { label: 'Button', klass: ButtonExamples, src: 'ButtonExamples' }, |
| 34 | + buttongroup: { label: 'Button Group', klass: ButtonGroupExamples, src: 'ButtonGroupExamples' }, |
| 35 | + datepicker: { label: 'Datepicker', klass: DatepickerExamples, src: 'DatepickerExamples' }, |
| 36 | + dropdownbutton: |
| 37 | + { label: 'Dropdown Button', klass: DropdownButtonExamples, src: 'DropdownButtonExamples' }, |
| 38 | + form: { label: 'Form', klass: FormExamples, src: 'FormExamples' }, |
| 39 | + grid: { label: 'Grid', klass: GridExamples, src: 'GridExamples' }, |
| 40 | + icon: { label: 'Icon', klass: IconExamples, src: 'IconExamples' }, |
| 41 | + lookup: { label: 'Lookup', klass: LookupExamples, src: 'LookupExamples' }, |
| 42 | + mediaobject: { label: 'Media Object', klass: MediaObjectExamples, src: 'MediaObjectExamples' }, |
| 43 | + modal: { label: 'Modal', klass: ModalExamples, src: 'ModalExamples' }, |
| 44 | + notification: { label: 'Notification', klass: NotificationExamples, src: 'NotificationExamples' }, |
| 45 | + pageheader: { label: 'Page Header', klass: PageHeaderExamples, src: 'PageHeaderExamples' }, |
| 46 | + popover: { label: 'Popovers', klass: PopoverExamples, src: 'PopoverExamples' }, |
| 47 | + tabs: { label: 'Tabs', klass: TabsExamples, src: 'TabsExamples' }, |
| 48 | + tree: { label: 'Tree', klass: TreeExamples, src: 'TreeExamples' }, |
| 49 | + spinner: { label: 'Spinners', klass: SpinnerExamples, src: 'SpinnerExamples' }, |
| 50 | + toggle: { label: 'Toggle', klass: ToggleExamples, src: 'ToggleExamples' }, |
| 51 | + fileselector: { label: 'File Selector', klass: FileSelectorExamples, src: 'FileSelectorExamples' }, |
| 52 | + card: { label: 'Card', klass: CardExamples, src: 'CardExamples' }, |
| 53 | +}; |
| 54 | + |
| 55 | +const GITHUB_EXAMPLE_SRC_DIR_URL = 'https://github.com/stomita/react-lightning-design-system/blob/master/examples/client/scripts/components/'; |
| 56 | + |
| 57 | +export default class Root extends React.Component { |
| 58 | + constructor() { |
| 59 | + super(); |
| 60 | + this.state = { section: 'button' }; |
| 61 | + } |
| 62 | + |
| 63 | + componentDidMount() { |
| 64 | + const routes = {}; |
| 65 | + for (const [section] of Object.entries(SECTIONS)) { |
| 66 | + routes[`/${section}`] = this.setState.bind(this, { section }); |
| 67 | + } |
| 68 | + routes['/'] = this.setState.bind(this, { section: 'button' }); |
| 69 | + /* eslint-disable new-cap */ |
| 70 | + const router = Router(routes); |
| 71 | + router.init(); |
| 72 | + } |
| 73 | + |
| 74 | + onSelectSection(e, props) { |
| 75 | + if (props.name) { |
| 76 | + location.hash = `#/${props.name}`; |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + render() { |
| 81 | + const targetSection = this.state.section; |
| 82 | + return ( |
| 83 | + <Grid frame> |
| 84 | + <Row> |
| 85 | + <Col className='slds-page-header'> |
| 86 | + <h1>Lightning Design System for React</h1> |
| 87 | + </Col> |
| 88 | + </Row> |
| 89 | + <Row cols={4} nowrap> |
| 90 | + <Col cols={1}> |
| 91 | + <Tree onNodeClick={ this.onSelectSection.bind(this) } toggleOnNodeClick> |
| 92 | + <TreeNode label='Components' defaultOpened> |
| 93 | + { |
| 94 | + Object.keys(SECTIONS).map((name, index) => { |
| 95 | + const section = SECTIONS[name]; |
| 96 | + return ( |
| 97 | + <TreeNode |
| 98 | + key={ index } |
| 99 | + name={ name } |
| 100 | + label={ section.label } |
| 101 | + leaf |
| 102 | + selected={ name === targetSection } |
| 103 | + /> |
| 104 | + ); |
| 105 | + }) |
| 106 | + } |
| 107 | + </TreeNode> |
| 108 | + </Tree> |
| 109 | + </Col> |
| 110 | + <Col cols={4} padded='large'> |
| 111 | + { |
| 112 | + Object.keys(SECTIONS).filter(name => name === targetSection) |
| 113 | + .map((name, index) => { |
| 114 | + const Example = SECTIONS[name].klass; |
| 115 | + const src = SECTIONS[name].src; |
| 116 | + return ( |
| 117 | + <div key={`child-${index}`}> |
| 118 | + <div style={ { textAlign: 'right' } }> |
| 119 | + <a |
| 120 | + target='_blank' |
| 121 | + rel='noopener noreferrer' |
| 122 | + href={ `${GITHUB_EXAMPLE_SRC_DIR_URL}${src}.js` } |
| 123 | + > |
| 124 | + View source file in Github |
| 125 | + </a> |
| 126 | + </div> |
| 127 | + <Example key={ index } /> |
| 128 | + </div> |
| 129 | + ); |
| 130 | + }) |
| 131 | + } |
| 132 | + </Col> |
| 133 | + </Row> |
| 134 | + </Grid> |
| 135 | + ); |
| 136 | + } |
| 137 | +} |
0 commit comments