-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
245 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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
54 changes: 54 additions & 0 deletions
54
packages/components/src/toggle-multiple-group-control/component.tsx
This file contains 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,54 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ForwardedRef } from 'react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
contextConnect, | ||
ContextSystemProvider, | ||
WordPressComponentProps, | ||
} from '../ui/context'; | ||
import type { ToggleMultipleGroupControlProps } from './types'; | ||
import { ToggleGroupControl } from '../toggle-group-control'; | ||
import { useContextSystem } from '../ui/context/use-context-system'; | ||
|
||
const contextProviderValue = { | ||
ToggleGroupControlOptionBase: { | ||
isMultiple: true, | ||
}, | ||
}; | ||
|
||
function UnconnectedToggleMultipleGroupControl( | ||
props: WordPressComponentProps< | ||
ToggleMultipleGroupControlProps, | ||
'div', | ||
false | ||
>, | ||
forwardedRef: ForwardedRef< any > | ||
) { | ||
const { | ||
onChange, // omit | ||
...otherProps | ||
} = useContextSystem( props, 'UnconnectedToggleMultipleGroupControl' ); | ||
|
||
return ( | ||
<ContextSystemProvider value={ contextProviderValue }> | ||
<ToggleGroupControl | ||
{ ...otherProps } | ||
isDeselectable | ||
__nextHasNoMarginBottom | ||
ref={ forwardedRef } | ||
/> | ||
</ContextSystemProvider> | ||
); | ||
} | ||
|
||
export const ToggleMultipleGroupControl = contextConnect( | ||
UnconnectedToggleMultipleGroupControl, | ||
'ToggleMultipleGroupControl' | ||
); | ||
|
||
export default ToggleMultipleGroupControl; |
This file contains 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 @@ | ||
export { ToggleMultipleGroupControl } from './component'; |
40 changes: 40 additions & 0 deletions
40
packages/components/src/toggle-multiple-group-control/option-icon.tsx
This file contains 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,40 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ForwardedRef } from 'react'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { forwardRef } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { ToggleGroupControlOptionIcon } from '../toggle-group-control'; | ||
import type { ToggleMultipleGroupControlOptionIconProps } from './types'; | ||
import type { WordPressComponentProps } from '../ui/context'; | ||
|
||
function UnforwardedToggleMultipleGroupControlOptionIcon( | ||
{ | ||
isPressed, | ||
...otherProps | ||
}: WordPressComponentProps< | ||
ToggleMultipleGroupControlOptionIconProps, | ||
'button', | ||
false | ||
>, | ||
ref: ForwardedRef< any > | ||
) { | ||
return ( | ||
<ToggleGroupControlOptionIcon | ||
{ ...otherProps } | ||
ref={ ref } | ||
aria-pressed={ isPressed } | ||
/> | ||
); | ||
} | ||
|
||
export const ToggleMultipleGroupControlOptionIcon = forwardRef( | ||
UnforwardedToggleMultipleGroupControlOptionIcon | ||
); |
70 changes: 70 additions & 0 deletions
70
packages/components/src/toggle-multiple-group-control/stories/index.tsx
This file contains 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,70 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
import { formatBold, formatItalic, formatUnderline } from '@wordpress/icons'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { ToggleMultipleGroupControl } from '../'; | ||
import { ToggleMultipleGroupControlOptionIcon } from '../option-icon'; | ||
|
||
const meta: ComponentMeta< typeof ToggleMultipleGroupControl > = { | ||
component: ToggleMultipleGroupControl, | ||
title: 'Components (Experimental)/ToggleMultipleGroupControl', | ||
subcomponents: { ToggleMultipleGroupControlOptionIcon }, | ||
argTypes: { | ||
help: { control: { type: 'text' } }, | ||
}, | ||
parameters: { | ||
controls: { expanded: true }, | ||
docs: { source: { state: 'open' } }, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
const Template: ComponentStory< typeof ToggleMultipleGroupControl > = ( | ||
props | ||
) => { | ||
const [ bold, setBold ] = useState( false ); | ||
const [ italic, setItalic ] = useState( false ); | ||
const [ underline, setUndeline ] = useState( false ); | ||
|
||
return ( | ||
<ToggleMultipleGroupControl { ...props }> | ||
<ToggleMultipleGroupControlOptionIcon | ||
value="bold" | ||
label="Bold" | ||
icon={ formatBold } | ||
isPressed={ bold } | ||
onClick={ () => setBold( ! bold ) } | ||
/> | ||
<ToggleMultipleGroupControlOptionIcon | ||
value="italic" | ||
label="Italic" | ||
icon={ formatItalic } | ||
isPressed={ italic } | ||
onClick={ () => setItalic( ! italic ) } | ||
/> | ||
<ToggleMultipleGroupControlOptionIcon | ||
value="underline" | ||
label="Underline" | ||
icon={ formatUnderline } | ||
isPressed={ underline } | ||
onClick={ () => setUndeline( ! underline ) } | ||
/> | ||
</ToggleMultipleGroupControl> | ||
); | ||
}; | ||
|
||
export const Default: ComponentStory< typeof ToggleMultipleGroupControl > = | ||
Template.bind( {} ); | ||
Default.args = { | ||
label: 'Label', | ||
}; |
Oops, something went wrong.