Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit c449916

Browse files
committed
improved examples and select knob
1 parent 1146515 commit c449916

File tree

8 files changed

+78
-29
lines changed

8 files changed

+78
-29
lines changed

docs/src/components/Knobs/KnobsBoolean.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class KnobsBoolean extends React.Component<any, any> {
2424

2525
return (
2626
<KnobsField>
27-
<KnobsControl>
27+
<KnobsControl textAlign="center">
2828
<input type="checkbox" defaultChecked={booleanValue} onChange={this.handleChange} />
2929
</KnobsControl>
3030
<KnobsLabel value={value} name={name} />

docs/src/components/Knobs/KnobsControl.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { createComponent } from 'react-fela'
2+
import { TextAlignProperty } from 'csstype'
23
import { pxToRem } from 'src/lib'
34

45
const KnobsControl = createComponent(
5-
() => ({
6+
({ textAlign = 'initial' }: { textAlign?: TextAlignProperty }) => ({
67
marginRight: pxToRem(5),
78
verticalAlign: 'middle',
8-
textAlign: 'center',
9+
textAlign,
910
}),
1011
'span',
1112
)
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { createComponent } from 'react-fela'
22
import { pxToRem } from 'src/lib'
33

4-
const KnobsField = createComponent(() => ({
4+
const KnobsField = createComponent(({ width = 60 }: { width?: number }) => ({
55
display: 'grid',
6-
gridTemplateColumns: `${pxToRem(60)} auto`,
6+
alignItems: 'center',
7+
gridTemplateColumns: `${pxToRem(width)} auto`,
78
}))
89

910
export default KnobsField

docs/src/components/Knobs/KnobsSelect.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface KnobsSelectProps {
1717
}
1818

1919
class KnobsSelect extends React.Component<KnobsSelectProps, {}> {
20-
private itemsMap: ObjectOf<KnobsSelectItem> = {}
20+
private itemsMap: ObjectOf<KnobsSelectItem>
2121

2222
public static propTypes = {
2323
onChange: PropTypes.func,
@@ -27,11 +27,16 @@ class KnobsSelect extends React.Component<KnobsSelectProps, {}> {
2727
}
2828

2929
componentDidMount() {
30+
this.itemsMap = {}
3031
this.props.items.forEach(item => {
3132
this.itemsMap[item.value] = item
3233
})
3334
}
3435

36+
componentWillUnmount() {
37+
this.itemsMap = {}
38+
}
39+
3540
render() {
3641
const { name, items } = this.props
3742
if (!items || !items.length) {
@@ -41,15 +46,17 @@ class KnobsSelect extends React.Component<KnobsSelectProps, {}> {
4146
const selectedItem = this.props.selectedItem || this.props.items[0]
4247

4348
return (
44-
<KnobsField>
49+
<KnobsField width={120}>
4550
<KnobsControl>
4651
<select value={selectedItem.value} onChange={this.handleChange}>
4752
{items.map(({ name, value }) => (
48-
<option value={value}>{name}</option>
53+
<option key={value} value={value}>
54+
{name}
55+
</option>
4956
))}
5057
</select>
5158
</KnobsControl>
52-
<KnobsLabel value={selectedItem.value} name={name} />
59+
<KnobsLabel value={selectedItem.name} name={name} />
5360
</KnobsField>
5461
)
5562
}
Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
import * as React from 'react'
22
import * as PropTypes from 'prop-types'
33
import * as _ from 'lodash'
4-
import Knobs from 'docs/src/components/Knobs/Knobs'
54
import { ProviderConsumer } from '@stardust-ui/react'
65

6+
import Knobs from 'docs/src/components/Knobs/Knobs'
7+
import { KnobsSelectItem } from 'docs/src/components/Knobs/KnobsSelect'
8+
79
type MenuExampleColorKnobsProps = {
810
onKnobChange: () => void
11+
overrides: { selectedItem?: KnobsSelectItem }
912
}
1013

11-
const MenuExampleColorKnobs = (props: MenuExampleColorKnobsProps) => {
12-
const { onKnobChange } = props
13-
14+
const MenuExampleColorKnobs = ({
15+
onKnobChange,
16+
overrides: { selectedItem },
17+
}: MenuExampleColorKnobsProps) => {
1418
return (
1519
<ProviderConsumer
1620
render={({ siteVariables: { colorScheme } }) => {
1721
const colorsArr = _.keys(colorScheme).map(color => ({
18-
name: _.upperCase(color),
22+
name: _.startCase(color),
1923
value: color,
2024
}))
2125

2226
return (
2327
<Knobs>
24-
<Knobs.Select name="Choose a color: " items={colorsArr} onChange={onKnobChange} />
28+
<Knobs.Select
29+
name="Color"
30+
items={colorsArr}
31+
onChange={onKnobChange}
32+
selectedItem={selectedItem}
33+
/>
2534
</Knobs>
2635
)
2736
}}
@@ -31,6 +40,11 @@ const MenuExampleColorKnobs = (props: MenuExampleColorKnobsProps) => {
3140

3241
MenuExampleColorKnobs.propTypes = {
3342
onKnobChange: PropTypes.func.isRequired,
43+
selectedItem: PropTypes.shape({ name: PropTypes.string, value: PropTypes.string }),
44+
}
45+
46+
MenuExampleColorKnobs.defaultProps = {
47+
selectedItem: { name: 'Primary', value: 'primary' },
3448
}
3549

3650
export default MenuExampleColorKnobs

docs/src/examples/components/Menu/Variations/MenuExampleColor.shorthand.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,25 @@ const MenuExampleColor = ({
2626
styles={{ justifyContent: 'left', justifyItems: 'left', alignItems: 'center' }}
2727
variables={{ gridGap: '10px' }}
2828
>
29-
<Text content={`${name} DEFAULT MENU:`} weight="bold" />
29+
<Text content="Default menu:" weight="bold" />
3030
<Menu defaultActiveIndex={0} color={value} items={items} />
31-
<Text content={`${name} PILLS MENU:`} weight="bold" />
31+
<Text content="Pills menu:" weight="bold" />
3232
<Menu defaultActiveIndex={0} color={value} pills items={items} />
33-
<Text content={`${name} POINTING MENU:`} weight="bold" />
33+
<Text content="Pointing menu:" weight="bold" />
3434
<Menu defaultActiveIndex={0} color={value} pointing items={items} />
35-
<Text content={`${name} VERTICAL POINTING MENU:`} weight="bold" />
35+
<Text content="Vertical pointing menu:" weight="bold" />
3636
<Menu defaultActiveIndex={0} color={value} vertical pointing items={items} />
37-
<Text content={`${name} UNDERLINED MENU:`} weight="bold" />
37+
<Text content="Underlined menu:" weight="bold" />
3838
<Menu defaultActiveIndex={0} color={value} underlined items={items} />
39-
<Text content={`${name} ICON MENU:`} weight="bold" />
39+
<Text content="Icon menu:" weight="bold" />
4040
<Menu defaultActiveIndex={0} color={value} items={iconItems} />
41-
<Text content={`${name} ICON ONLY MENU:`} weight="bold" />
41+
<Text content="Icon only menu:" weight="bold" />
4242
<Menu
4343
defaultActiveIndex={0}
4444
color={value}
4545
iconOnly
4646
items={iconItems.map(item => _.pick(item, ['key', 'icon']))}
4747
/>
48-
<Text content={`UNDERLINED MENU (mutiple colors):`} weight="bold" />
49-
{/* <Menu
50-
defaultActiveIndex={0}
51-
underlined
52-
color={{ foreground: value, background: value, border: value }}
53-
items={items}
54-
/> */}
5548
</Grid>
5649
)
5750

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as React from 'react'
2+
import * as _ from 'lodash'
3+
import { Menu, ProviderConsumer } from '@stardust-ui/react'
4+
5+
const items = [
6+
{ key: 'editorials', content: 'Editorials' },
7+
{ key: 'review', content: 'Reviews' },
8+
{ key: 'events', content: 'Upcoming Events' },
9+
]
10+
11+
const MenuExampleColorComplex = () => (
12+
<ProviderConsumer
13+
render={({ siteVariables: { colorScheme } }) => {
14+
const colors = _.keys(colorScheme)
15+
16+
return (
17+
<Menu
18+
defaultActiveIndex={0}
19+
underlined
20+
color={{ foreground: colors[3], background: colors[1], border: colors[0] }}
21+
items={items}
22+
/>
23+
)
24+
}}
25+
/>
26+
)
27+
28+
export default MenuExampleColorComplex

docs/src/examples/components/Menu/Variations/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ const Variations = () => (
2424
description="A Menu can have different colors."
2525
examplePath="components/Menu/Variations/MenuExampleColor"
2626
/>
27+
<ComponentExample
28+
title="Complex Colored Menu"
29+
description="A Menu can have different colors for different areas (border, background, foregroung)."
30+
examplePath="components/Menu/Variations/MenuExampleColorComplex"
31+
/>
2732
</ExampleSection>
2833
)
2934

0 commit comments

Comments
 (0)