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 51
feat(Toolbar): add component #1408
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
79e1f5a
wip
levithomason f15f072
basic Toolbar components scaffolding
miroslavstastny 037d7dd
isConformant tests for Toolbar components
miroslavstastny b53537e
ToolbarItem onClick
miroslavstastny ab20e1f
Merge remote-tracking branch 'origin/master' into proto/calling-scree…
miroslavstastny 6ccdb01
fix imports after merging latest master
miroslavstastny 62bc4f0
text editor toolbar example
miroslavstastny 365f48c
basic styles
miroslavstastny cf57e02
active and disabled props
miroslavstastny 16321b9
cleanup
miroslavstastny db486ba
screener steps
miroslavstastny 64a7573
Merge remote-tracking branch 'origin/master' into proto/calling-scree…
miroslavstastny d3d1abb
use colorScheme
miroslavstastny b371e92
Merge remote-tracking branch 'origin/master' into proto/calling-scree…
miroslavstastny 01937e5
add ToolbarDivider and ToolbarItem variables
miroslavstastny f12b9f6
Merge remote-tracking branch 'origin/master' into proto/calling-scree…
miroslavstastny d61a8dc
changelog
miroslavstastny 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
3 changes: 3 additions & 0 deletions
3
docs/src/examples/components/Toolbar/Types/ToolbarExampleEditor.shorthand.steps.ts
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,3 @@ | ||
| const config: ScreenerTestsConfig = { themes: ['teams', 'teamsDark', 'teamsHighContrast'] } | ||
|
|
||
| export default config |
63 changes: 63 additions & 0 deletions
63
docs/src/examples/components/Toolbar/Types/ToolbarExampleEditor.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,63 @@ | ||
| import * as React from 'react' | ||
| import { Toolbar } from '@stardust-ui/react' | ||
|
|
||
| const ToolbarExampleShorthand = () => { | ||
| const [isBold, setBold] = React.useState(true) | ||
| const [isItalic, setItalic] = React.useState(false) | ||
| const [isUnderline, setUnderline] = React.useState(false) | ||
| const [isStrike, setStrike] = React.useState(false) | ||
|
|
||
| return ( | ||
| <Toolbar | ||
| items={[ | ||
| { | ||
| key: 'bold', | ||
| active: isBold, | ||
| icon: { name: 'bold', outline: true }, | ||
| onClick: () => { | ||
| setBold(!isBold) | ||
| }, | ||
| }, | ||
| { | ||
| key: 'italic', | ||
| active: isItalic, | ||
| icon: { name: 'italic', outline: true }, | ||
| onClick: () => { | ||
| setItalic(!isItalic) | ||
| }, | ||
| }, | ||
| { | ||
| key: 'underline', | ||
| active: isUnderline, | ||
| icon: { name: 'underline', outline: true }, | ||
| onClick: () => { | ||
| setUnderline(!isUnderline) | ||
| }, | ||
| }, | ||
| { | ||
| key: 'strike', | ||
| active: isStrike, | ||
| disabled: true, | ||
| icon: { name: 'strike', outline: true }, | ||
| onClick: () => { | ||
| setStrike(!isStrike) | ||
| }, | ||
| }, | ||
| { key: 'divider1', kind: 'divider' }, | ||
| { key: 'highlight', icon: { name: 'highlight', outline: true } }, | ||
| { key: 'font-color', icon: { name: 'font-color', outline: true } }, | ||
| { key: 'font-size', icon: { name: 'font-size', outline: true } }, | ||
| { key: 'remove-format', icon: { name: 'remove-format', outline: true } }, | ||
| { key: 'divider2', kind: 'divider' }, | ||
| { key: 'outdent', icon: { name: 'outdent', outline: true } }, | ||
| { key: 'indent', icon: { name: 'indent', outline: true } }, | ||
| { key: 'bullets', icon: { name: 'bullets', outline: true } }, | ||
| { key: 'number-list', icon: { name: 'number-list', outline: true } }, | ||
| { key: 'divider3', kind: 'divider' }, | ||
| { key: 'more', icon: { name: 'more', outline: true } }, | ||
| ]} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| export default ToolbarExampleShorthand |
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,15 @@ | ||
| import * as React from 'react' | ||
| import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample' | ||
| import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection' | ||
|
|
||
| const Types = () => ( | ||
| <ExampleSection title="Types"> | ||
| <ComponentExample | ||
| title="Text editor toolbar" | ||
| description="A Toolbar use case for a text editor." | ||
| examplePath="components/Toolbar/Types/ToolbarExampleEditor" | ||
| /> | ||
| </ExampleSection> | ||
| ) | ||
|
|
||
| export default Types |
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,11 @@ | ||
| import * as React from 'react' | ||
|
|
||
| import Types from './Types' | ||
|
|
||
| const ToolbarExamples = () => ( | ||
| <> | ||
| <Types /> | ||
| </> | ||
| ) | ||
|
|
||
| export default ToolbarExamples |
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 |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import * as React from 'react' | ||
| import * as _ from 'lodash' | ||
| import * as customPropTypes from '@stardust-ui/react-proptypes' | ||
|
|
||
| import { | ||
| childrenExist, | ||
| createShorthandFactory, | ||
| UIComponent, | ||
| UIComponentProps, | ||
| ContentComponentProps, | ||
| ChildrenComponentProps, | ||
| commonPropTypes, | ||
| ColorComponentProps, | ||
| } from '../../lib' | ||
| import { Accessibility } from '../../lib/accessibility/types' | ||
| import { defaultBehavior } from '../../lib/accessibility' | ||
| import { ShorthandCollection, WithAsProp, withSafeTypeForAs } from '../../types' | ||
|
|
||
| import ToolbarItem from './ToolbarItem' | ||
| import ToolbarDivider from './ToolbarDivider' | ||
| import ToolbarRadioGroup from './ToolbarRadioGroup' | ||
|
|
||
| export type ToolbarItemShorthandKinds = 'divider' | 'item' | 'group' | ||
|
|
||
| export interface ToolbarProps | ||
| extends UIComponentProps, | ||
| ContentComponentProps, | ||
| ChildrenComponentProps, | ||
| ColorComponentProps { | ||
| /** | ||
| * Accessibility behavior if overridden by the user. | ||
| * @default defaultBehavior | ||
| */ | ||
| accessibility?: Accessibility | ||
|
|
||
| /** Shorthand array of props for Toolbar. */ | ||
| items?: ShorthandCollection<ToolbarItemShorthandKinds> | ||
| } | ||
|
|
||
| class Toolbar extends UIComponent<WithAsProp<ToolbarProps>, any> { | ||
| static create: Function | ||
|
|
||
| static className = 'ui-toolbar' | ||
|
|
||
| static displayName = 'Toolbar' | ||
|
|
||
| static propTypes = { | ||
| ...commonPropTypes.createCommon(), | ||
| items: customPropTypes.collectionShorthandWithKindProp(['divider', 'item', 'group']), | ||
| } | ||
|
|
||
| static defaultProps = { | ||
| accessibility: defaultBehavior, | ||
| } | ||
|
|
||
| static Item = ToolbarItem | ||
| static Divider = ToolbarDivider | ||
| static RadioGroup = ToolbarRadioGroup | ||
|
|
||
| handleItemOverrides = variables => predefinedProps => ({ | ||
| variables: { | ||
| ...variables, | ||
| ...predefinedProps.variables, | ||
| }, | ||
| }) | ||
|
|
||
| private renderItems(items, variables) { | ||
| const itemOverridesFn = this.handleItemOverrides(variables) | ||
| return _.map(items, (item, index) => { | ||
| const kind = _.get(item, 'kind', 'item') | ||
|
|
||
| switch (kind) { | ||
| case 'divider': | ||
| return ToolbarDivider.create(item, { overrideProps: itemOverridesFn }) | ||
| case 'group': | ||
| return ToolbarRadioGroup.create(item, { overrideProps: itemOverridesFn }) | ||
| default: | ||
| return ToolbarItem.create(item, { overrideProps: itemOverridesFn }) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| renderComponent({ | ||
| accessibility, | ||
| ElementType, | ||
| classes, | ||
| variables, | ||
| unhandledProps, | ||
| }): React.ReactNode { | ||
| const { children, items } = this.props | ||
|
|
||
| return ( | ||
| <ElementType className={classes.root} {...accessibility.attributes.root} {...unhandledProps}> | ||
| {childrenExist(children) ? children : this.renderItems(items, variables)} | ||
| </ElementType> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| Toolbar.create = createShorthandFactory({ Component: Toolbar, mappedProp: 'content' }) | ||
|
|
||
| /** | ||
| * A Toolbar component displays grouped actions. | ||
| */ | ||
| export default withSafeTypeForAs<typeof Toolbar, ToolbarProps>(Toolbar) | ||
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,57 @@ | ||
| import * as React from 'react' | ||
| import { | ||
| ChildrenComponentProps, | ||
| ContentComponentProps, | ||
| createShorthandFactory, | ||
| UIComponentProps, | ||
| UIComponent, | ||
| commonPropTypes, | ||
| } from '../../lib' | ||
| import { Accessibility } from '../../lib/accessibility/types' | ||
| import { WithAsProp, withSafeTypeForAs } from '../../types' | ||
| import { defaultBehavior } from '../../lib/accessibility' | ||
|
|
||
| export interface ToolbarDividerProps | ||
| extends UIComponentProps, | ||
| ChildrenComponentProps, | ||
| ContentComponentProps { | ||
| /** | ||
| * Accessibility behavior if overridden by the user. | ||
| * @default defaultBehavior | ||
| */ | ||
| accessibility?: Accessibility | ||
| } | ||
|
|
||
| class ToolbarDivider extends UIComponent<WithAsProp<ToolbarDividerProps>> { | ||
| static displayName = 'ToolbarDivider' | ||
|
|
||
| static create: Function | ||
|
|
||
| static className = 'ui-toolbar__divider' | ||
|
|
||
| static propTypes = { | ||
| ...commonPropTypes.createCommon(), | ||
| } | ||
|
|
||
| static defaultProps = { | ||
| accessibility: defaultBehavior as Accessibility, | ||
| } | ||
|
|
||
| renderComponent({ ElementType, classes, unhandledProps, accessibility }) { | ||
| return ( | ||
| <ElementType | ||
| {...accessibility.attributes.root} | ||
| {...unhandledProps} | ||
| className={classes.root} | ||
| /> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| ToolbarDivider.create = createShorthandFactory({ Component: ToolbarDivider, mappedProp: 'content' }) | ||
|
|
||
| /** | ||
| * Toolbar divider. | ||
| * Adds visual non-selectable separator between items. | ||
| */ | ||
| export default withSafeTypeForAs<typeof ToolbarDivider, ToolbarDividerProps>(ToolbarDivider) |
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.
Uh oh!
There was an error while loading. Please reload this page.