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

Commit 1146515

Browse files
committed
implemented knobs for the examples
1 parent 7d08a74 commit 1146515

File tree

3 files changed

+79
-43
lines changed

3 files changed

+79
-43
lines changed

docs/src/components/Knobs/Knobs.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import KnobsValue from './KnobsValue'
88

99
import KnobsBoolean from './KnobsBoolean'
1010
import KnobsScalar from './KnobsScalar'
11+
import KnobsSelect from './KnobsSelect'
1112

1213
const Knobs: any = createComponent(
1314
() => ({
@@ -31,12 +32,14 @@ const Knobs: any = createComponent(
3132
}),
3233
'div',
3334
)
35+
3436
Knobs.Field = KnobsField
3537
Knobs.Control = KnobsControl
3638
Knobs.Label = KnobsLabel
3739
Knobs.Value = KnobsValue
3840

3941
Knobs.Boolean = KnobsBoolean
4042
Knobs.Scalar = KnobsScalar
43+
Knobs.Select = KnobsSelect
4144

4245
export default Knobs
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as React from 'react'
2+
import * as PropTypes from 'prop-types'
3+
import * as _ from 'lodash'
4+
import Knobs from 'docs/src/components/Knobs/Knobs'
5+
import { ProviderConsumer } from '@stardust-ui/react'
6+
7+
type MenuExampleColorKnobsProps = {
8+
onKnobChange: () => void
9+
}
10+
11+
const MenuExampleColorKnobs = (props: MenuExampleColorKnobsProps) => {
12+
const { onKnobChange } = props
13+
14+
return (
15+
<ProviderConsumer
16+
render={({ siteVariables: { colorScheme } }) => {
17+
const colorsArr = _.keys(colorScheme).map(color => ({
18+
name: _.upperCase(color),
19+
value: color,
20+
}))
21+
22+
return (
23+
<Knobs>
24+
<Knobs.Select name="Choose a color: " items={colorsArr} onChange={onKnobChange} />
25+
</Knobs>
26+
)
27+
}}
28+
/>
29+
)
30+
}
31+
32+
MenuExampleColorKnobs.propTypes = {
33+
onKnobChange: PropTypes.func.isRequired,
34+
}
35+
36+
export default MenuExampleColorKnobs
Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react'
22
import * as _ from 'lodash'
3-
import { Menu, ProviderConsumer, Grid, Text } from '@stardust-ui/react'
3+
import { Menu, Grid, Text } from '@stardust-ui/react'
44

55
const items = [
66
{ key: 'editorials', content: 'Editorials' },
@@ -14,48 +14,45 @@ const iconItems = [
1414
{ key: 'search', icon: 'search' },
1515
]
1616

17-
const MenuExampleColor = () => (
18-
<ProviderConsumer
19-
render={({ siteVariables: { colorScheme } }) => {
20-
const colorsArr = _.keys(colorScheme)
21-
const colors = _.times(7, num => colorsArr[num % colorsArr.length])
22-
23-
return (
24-
<Grid
25-
columns="repeat(2, auto)"
26-
styles={{ justifyContent: 'left', justifyItems: 'left', alignItems: 'center' }}
27-
variables={{ gridGap: '10px' }}
28-
>
29-
<Text content={`${_.upperCase(colors[0])} DEFAULT MENU:`} weight="bold" />
30-
<Menu defaultActiveIndex={0} color={colors[0]} items={items} />
31-
<Text content={`${_.upperCase(colors[1])} PILLS MENU:`} weight="bold" />
32-
<Menu defaultActiveIndex={0} color={colors[1]} pills items={items} />
33-
<Text content={`${_.upperCase(colors[2])} POINTING MENU:`} weight="bold" />
34-
<Menu defaultActiveIndex={0} color={colors[2]} pointing items={items} />
35-
<Text content={`${_.upperCase(colors[3])} VERTICAL POINTING MENU:`} weight="bold" />
36-
<Menu defaultActiveIndex={0} color={colors[3]} vertical pointing items={items} />
37-
<Text content={`${_.upperCase(colors[4])} UNDERLINED MENU:`} weight="bold" />
38-
<Menu defaultActiveIndex={0} color={colors[4]} underlined items={items} />
39-
<Text content={`${_.upperCase(colors[5])} ICON MENU:`} weight="bold" />
40-
<Menu defaultActiveIndex={0} color={colors[5]} items={iconItems} />
41-
<Text content={`${_.upperCase(colors[6])} ICON ONLY MENU:`} weight="bold" />
42-
<Menu
43-
defaultActiveIndex={0}
44-
color={colors[6]}
45-
iconOnly
46-
items={iconItems.map(item => _.pick(item, ['key', 'icon']))}
47-
/>
48-
<Text content={`UNDERLINED MENU (mutiple colors):`} weight="bold" />
49-
<Menu
50-
defaultActiveIndex={0}
51-
underlined
52-
color={{ foreground: colors[4], background: colors[5], border: colors[1] }}
53-
items={items}
54-
/>
55-
</Grid>
56-
)
57-
}}
58-
/>
17+
const MenuExampleColor = ({
18+
knobs: {
19+
selectedItem: { name, value },
20+
},
21+
}: {
22+
knobs: { selectedItem: { name: string; value: string } }
23+
}) => (
24+
<Grid
25+
columns="repeat(2, auto)"
26+
styles={{ justifyContent: 'left', justifyItems: 'left', alignItems: 'center' }}
27+
variables={{ gridGap: '10px' }}
28+
>
29+
<Text content={`${name} DEFAULT MENU:`} weight="bold" />
30+
<Menu defaultActiveIndex={0} color={value} items={items} />
31+
<Text content={`${name} PILLS MENU:`} weight="bold" />
32+
<Menu defaultActiveIndex={0} color={value} pills items={items} />
33+
<Text content={`${name} POINTING MENU:`} weight="bold" />
34+
<Menu defaultActiveIndex={0} color={value} pointing items={items} />
35+
<Text content={`${name} VERTICAL POINTING MENU:`} weight="bold" />
36+
<Menu defaultActiveIndex={0} color={value} vertical pointing items={items} />
37+
<Text content={`${name} UNDERLINED MENU:`} weight="bold" />
38+
<Menu defaultActiveIndex={0} color={value} underlined items={items} />
39+
<Text content={`${name} ICON MENU:`} weight="bold" />
40+
<Menu defaultActiveIndex={0} color={value} items={iconItems} />
41+
<Text content={`${name} ICON ONLY MENU:`} weight="bold" />
42+
<Menu
43+
defaultActiveIndex={0}
44+
color={value}
45+
iconOnly
46+
items={iconItems.map(item => _.pick(item, ['key', 'icon']))}
47+
/>
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+
/> */}
55+
</Grid>
5956
)
6057

6158
export default MenuExampleColor

0 commit comments

Comments
 (0)