Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 19x 19x 19x 19x 19x 34x | import _, { omit } from 'lodash'; import React from 'react'; import PropTypes from 'prop-types'; import { lucidClassNames } from '../../util/style-helpers'; import { findTypes, getFirst, Overwrite, StandardProps, } from '../../util/component-types'; import { buildModernHybridComponent } from '../../util/state-management'; import * as reducers from './VerticalTabs.reducers'; import { IVerticalListMenuItemProps, VerticalListMenuDumb as VerticalListMenu, } from '../VerticalListMenu/VerticalListMenu'; const cx = lucidClassNames.bind('&-VerticalTabs'); const { string, number, bool, func } = PropTypes; /** Vertical Tabs Tab Child Component */ export interface IVerticalTabsTabProps extends StandardProps { /** Determines if the Tab is selected */ isSelected?: boolean; /** Custom title for the tab */ Title?: string; } const Tab = (_props: IVerticalTabsTabProps): null => null; Tab.displayName = 'VerticalTabs.Tab'; Tab.peek = { description: `Content that will be rendered in a tab. Be sure to nest a \`Title\` inside each \`Tab\` or provide it as a prop.`, }; Tab.propName = 'Tab'; Tab.propTypes = { /** Determines if the Tab is selected. */ isSelected: bool, }; /** Vertical Tabs Title Child Component */ const Title = (_props: StandardProps): null => null; Title.displayName = 'VerticalTabs.Title'; Title.peek = { description: `A \`Title\` can be provided as a child or prop to a \`Tab\`.`, }; Title.propName = 'Title'; /** Vertical Tabs Component */ interface IVerticalTabsPropsRaw extends StandardProps { /** * Custom Tab component (alias for `VerticalTabs.Tab`) */ Tab?: React.ReactNode; /** * Custom Title component (alias for `VerticalTabs.Title`) */ Title?: React.ReactNode; /** * Indicates which of the \`VerticalTabs.Tab\` children is currently selected */ selectedIndex: number; /** * Callback fired when the user selects a \`VerticalListMenu.Item\`. */ onSelect: ( index: number, { event, props, }: { event: React.MouseEvent; props: IVerticalListMenuItemProps; } ) => void; } export type IVerticalTabsProps = Overwrite< React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, IVerticalTabsPropsRaw >; /** Default props for the VerticalTabs component */ const defaultProps = { selectedIndex: 0, onSelect: _.noop, }; export interface IVerticalTabsState { selectedIndex: number; } class VerticalTabs extends React.Component< IVerticalTabsProps, IVerticalTabsState > { static displayName = 'VerticalTabs'; static propTypes = { /** Class names that are appended to the defaults. */ className: string, /** Indicates which of the \`VerticalTabs.Tab\` children is currently selected. The index of the last \`VerticalTabs.Tab\` child with \`isSelected\` equal to \`true\` takes precedence over this prop. */ selectedIndex: number, /** Callback for when the user clicks a tab. Called with the index of the tab that was clicked. Signature: \`(index, { event, props}) => {}\` */ onSelect: func, }; static defaultProps = defaultProps; static reducers = reducers; static Tab = Tab; static Title = Title; static peek = { description: `\`VerticalTabs\` provides vertically tabbed navigation. It has a flexible interface that allows tab content to be passed as regular React children or through props.`, categories: ['navigation'], madeFrom: ['VerticalListMenu'], }; render(): React.ReactNode { const { className, onSelect, selectedIndex, ...passThroughs } = this.props; // Grab props array from each Tab const tabChildProps = _.map( findTypes(this.props, VerticalTabs.Tab), 'props' ); const selectedIndexFromChildren = _.findLastIndex(tabChildProps, { isSelected: true, }); const actualSelectedIndex = selectedIndexFromChildren !== -1 ? selectedIndexFromChildren : selectedIndex; return ( <div {...omit(passThroughs, [ 'className', 'selectedIndex', 'onSelect', 'initialState', 'callbackId', ])} className={cx('&', className)} > <VerticalListMenu selectedIndices={[actualSelectedIndex]} onSelect={onSelect} > {_.map(tabChildProps, (tabChildProp, index) => ( <VerticalListMenu.Item className={cx('&-Tab', { '&-Tab-is-active': actualSelectedIndex === index, })} key={index} > <span className={cx('&-Tab-content')}> {_.get( getFirst(tabChildProp, VerticalTabs.Title), 'props.children', '' )} </span> </VerticalListMenu.Item> ))} </VerticalListMenu> <div className={cx('&-content')}> {_.get(tabChildProps, [actualSelectedIndex, 'children'])} </div> </div> ); } } export default buildModernHybridComponent< IVerticalTabsProps, IVerticalTabsState, typeof VerticalTabs >(VerticalTabs as any, { reducers }); export { VerticalTabs as VerticalTabsDumb }; |