This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
feat(menu): color prop and complex scheme #756
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { createComponent } from 'react-fela' | ||
import { pxToRem } from 'src/lib' | ||
|
||
const KnobsField = createComponent(() => ({ | ||
const KnobsField = createComponent(({ width = 60 }: { width?: number }) => ({ | ||
display: 'grid', | ||
gridTemplateColumns: `${pxToRem(60)} auto`, | ||
alignItems: 'center', | ||
gridTemplateColumns: `${pxToRem(width)} auto`, | ||
})) | ||
|
||
export default KnobsField |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import * as PropTypes from 'prop-types' | ||
import * as React from 'react' | ||
import * as _ from 'lodash' | ||
|
||
import KnobsField from './KnobsField' | ||
import KnobsLabel from './KnobsLabel' | ||
import KnobsControl from './KnobsControl' | ||
import { ObjectOf } from 'types/utils' | ||
|
||
export type KnobsSelectItem = { name: string; value: string } | ||
|
||
export interface KnobsSelectProps { | ||
onChange?: (data: KnobsSelectProps) => void | ||
name?: string | ||
items?: KnobsSelectItem[] | ||
selectedItem?: KnobsSelectItem | ||
} | ||
|
||
class KnobsSelect extends React.Component<KnobsSelectProps, {}> { | ||
private itemsMap: ObjectOf<KnobsSelectItem> | ||
|
||
public static propTypes = { | ||
onChange: PropTypes.func, | ||
name: PropTypes.string.isRequired, | ||
items: PropTypes.arrayOf(PropTypes.shape({ name: PropTypes.string, value: PropTypes.string })), | ||
selectedItem: PropTypes.shape({ name: PropTypes.string, value: PropTypes.string }), | ||
} | ||
|
||
componentDidMount() { | ||
this.itemsMap = {} | ||
this.props.items.forEach(item => { | ||
this.itemsMap[item.value] = item | ||
}) | ||
} | ||
|
||
componentWillUnmount() { | ||
this.itemsMap = {} | ||
} | ||
|
||
render() { | ||
const { name, items } = this.props | ||
if (!items || !items.length) { | ||
return null | ||
} | ||
|
||
const selectedItem = this.props.selectedItem || this.props.items[0] | ||
|
||
return ( | ||
<KnobsField width={120}> | ||
<KnobsControl> | ||
<select value={selectedItem.value} onChange={this.handleChange}> | ||
{items.map(({ name, value }) => ( | ||
<option key={value} value={value}> | ||
{name} | ||
</option> | ||
))} | ||
</select> | ||
</KnobsControl> | ||
<KnobsLabel value={selectedItem.name} name={name} /> | ||
</KnobsField> | ||
) | ||
} | ||
|
||
private handleChange = (e: React.SyntheticEvent<HTMLElement>) => { | ||
this.props.onChange({ selectedItem: this.itemsMap[_.get(e, 'target.value')] }) | ||
} | ||
} | ||
|
||
export default KnobsSelect |
50 changes: 50 additions & 0 deletions
50
docs/src/examples/components/Menu/Variations/MenuExampleColor.knobs.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as React from 'react' | ||
import * as PropTypes from 'prop-types' | ||
import * as _ from 'lodash' | ||
import { ProviderConsumer } from '@stardust-ui/react' | ||
|
||
import Knobs from 'docs/src/components/Knobs/Knobs' | ||
import { KnobsSelectItem } from 'docs/src/components/Knobs/KnobsSelect' | ||
|
||
type MenuExampleColorKnobsProps = { | ||
onKnobChange: () => void | ||
overrides: { selectedItem?: KnobsSelectItem } | ||
} | ||
|
||
const MenuExampleColorKnobs = ({ | ||
onKnobChange, | ||
overrides: { selectedItem }, | ||
}: MenuExampleColorKnobsProps) => { | ||
return ( | ||
<ProviderConsumer | ||
render={({ siteVariables: { colorScheme } }) => { | ||
const colorsArr = _.keys(colorScheme).map(color => ({ | ||
name: _.startCase(color), | ||
value: color, | ||
})) | ||
|
||
return ( | ||
<Knobs> | ||
<Knobs.Select | ||
name="Color" | ||
items={colorsArr} | ||
onChange={onKnobChange} | ||
selectedItem={selectedItem} | ||
/> | ||
</Knobs> | ||
) | ||
}} | ||
/> | ||
) | ||
} | ||
|
||
MenuExampleColorKnobs.propTypes = { | ||
onKnobChange: PropTypes.func.isRequired, | ||
selectedItem: PropTypes.shape({ name: PropTypes.string, value: PropTypes.string }), | ||
} | ||
|
||
MenuExampleColorKnobs.defaultProps = { | ||
selectedItem: { name: 'Primary', value: 'primary' }, | ||
} | ||
|
||
export default MenuExampleColorKnobs |
51 changes: 51 additions & 0 deletions
51
docs/src/examples/components/Menu/Variations/MenuExampleColor.shorthand.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as React from 'react' | ||
import * as _ from 'lodash' | ||
import { Menu, Grid, Text } from '@stardust-ui/react' | ||
|
||
const items = [ | ||
{ key: 'editorials', content: 'Editorials' }, | ||
{ key: 'review', content: 'Reviews' }, | ||
{ key: 'events', content: 'Upcoming Events' }, | ||
] | ||
|
||
const iconItems = [ | ||
{ key: 'home', content: 'Home', icon: 'home' }, | ||
{ key: 'users', content: 'Users', icon: 'users' }, | ||
{ key: 'search', icon: 'search' }, | ||
] | ||
|
||
const MenuExampleColor = ({ | ||
knobs: { | ||
selectedItem: { name, value }, | ||
}, | ||
}: { | ||
knobs: { selectedItem: { name: string; value: string } } | ||
}) => ( | ||
<Grid | ||
columns="repeat(2, auto)" | ||
styles={{ justifyContent: 'left', justifyItems: 'left', alignItems: 'center' }} | ||
variables={{ gridGap: '10px' }} | ||
> | ||
<Text content="Default menu:" weight="bold" /> | ||
<Menu defaultActiveIndex={0} color={value} items={items} /> | ||
<Text content="Pills menu:" weight="bold" /> | ||
<Menu defaultActiveIndex={0} color={value} pills items={items} /> | ||
<Text content="Pointing menu:" weight="bold" /> | ||
<Menu defaultActiveIndex={0} color={value} pointing items={items} /> | ||
<Text content="Vertical pointing menu:" weight="bold" /> | ||
<Menu defaultActiveIndex={0} color={value} vertical pointing items={items} /> | ||
<Text content="Underlined menu:" weight="bold" /> | ||
<Menu defaultActiveIndex={0} color={value} underlined items={items} /> | ||
<Text content="Icon menu:" weight="bold" /> | ||
<Menu defaultActiveIndex={0} color={value} items={iconItems} /> | ||
<Text content="Icon only menu:" weight="bold" /> | ||
<Menu | ||
defaultActiveIndex={0} | ||
color={value} | ||
iconOnly | ||
items={iconItems.map(item => _.pick(item, ['key', 'icon']))} | ||
/> | ||
</Grid> | ||
) | ||
|
||
export default MenuExampleColor | ||
28 changes: 28 additions & 0 deletions
28
docs/src/examples/components/Menu/Variations/MenuExampleColorComplex.shorthand.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as React from 'react' | ||
import * as _ from 'lodash' | ||
import { Menu, ProviderConsumer } from '@stardust-ui/react' | ||
|
||
const items = [ | ||
{ key: 'editorials', content: 'Editorials' }, | ||
{ key: 'review', content: 'Reviews' }, | ||
{ key: 'events', content: 'Upcoming Events' }, | ||
] | ||
|
||
const MenuExampleColorComplex = () => ( | ||
<ProviderConsumer | ||
render={({ siteVariables: { colorScheme } }) => { | ||
const colors = _.keys(colorScheme) | ||
|
||
return ( | ||
<Menu | ||
defaultActiveIndex={0} | ||
underlined | ||
color={{ foreground: colors[3], background: colors[1], border: colors[0] }} | ||
items={items} | ||
/> | ||
) | ||
}} | ||
/> | ||
) | ||
|
||
export default MenuExampleColorComplex |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for tracking @layershifter 's comment in: #712 (comment)
will address
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bare minimum examples
Reference SUIR for examples of clean Menu color examples. Let's not put so much information in a single example.
https://react.semantic-ui.com/collections/menu/#variations-colored
Definition only, avoid large permutations
The doc page should only be a "definition" of the component right now. That is a single example for each thing the menu can do, usually one example per prop.
At this point, let's not add examples for all possible permutations of what the menu can do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@levithomason
in SUIR there are not that many versions of Menus; I just introduced a Select Knob at @layershifter 's proposal and now we have examples that look like this:
TODO - introduce screenshot
We can separate these into different example files where we reuse the knob or we can add a knob on every example for the color, but because of the way knobs are implemented we need to have a
.knobs.tsx
file for every example, which is a lot of duplicationwhat do you think?