-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storybook: Add story for TypographyPanel #35293
Merged
Merged
Changes from 1 commit
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 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
217 changes: 217 additions & 0 deletions
217
packages/components/src/tools-panel/stories/typography-panel.js
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,217 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
__experimentalFontAppearanceControl as FontAppearanceControl, | ||
__experimentalFontFamilyControl as FontFamilyControl, | ||
__experimentalLetterSpacingControl as LetterSpacingControl, | ||
LineHeightControl, | ||
} from '@wordpress/block-editor'; | ||
import { | ||
FontSizePicker, | ||
__experimentalRadio as Radio, | ||
__experimentalRadioGroup as RadioGroup, | ||
} from '@wordpress/components'; | ||
import { useState } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { ToolsPanel, ToolsPanelItem } from '..'; | ||
import Panel from '../../panel'; | ||
import { ControlLabel } from '../../ui/control-label'; | ||
import { FormGroup } from '../../ui/form-group'; | ||
mirka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// These options match the theme.json typography schema | ||
const fontFamilies = [ | ||
{ | ||
fontFamily: | ||
'-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif', | ||
slug: 'system-fonts', | ||
name: 'System Fonts', | ||
}, | ||
{ | ||
fontFamily: | ||
'Consolas, "Andale Mono WT", "Andale Mono", "Lucida Console", "Lucida Sans Typewriter", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Liberation Mono", "Nimbus Mono L", Monaco, "Courier New", Courier, monospace', | ||
name: 'Monospace', | ||
slug: 'monospace', | ||
}, | ||
{ | ||
fontFamily: | ||
'Hoefler Text, Baskerville Old Face, Garamond, Times New Roman, serif', | ||
name: 'Serif', | ||
slug: 'hoefler-times-new-roman', | ||
}, | ||
]; | ||
const fontSizes = [ | ||
{ | ||
slug: 'small', | ||
size: '1rem', | ||
name: 'Small', | ||
}, | ||
{ | ||
slug: 'normal', | ||
size: '1.25rem', | ||
name: 'Normal', | ||
}, | ||
{ | ||
slug: 'medium', | ||
size: '1.5rem', | ||
name: 'medium', | ||
}, | ||
{ | ||
slug: 'large', | ||
size: '2rem', | ||
name: 'Large', | ||
}, | ||
{ | ||
slug: 'extra-large', | ||
size: '3rem', | ||
name: 'Extra large', | ||
}, | ||
]; | ||
|
||
const LetterCaseControl = ( props ) => { | ||
mirka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ( | ||
<FormGroup> | ||
<ControlLabel>Letter Case</ControlLabel> | ||
<RadioGroup label="Letter Case" { ...props }> | ||
<Radio value="uppercase" aria-label="Uppercase"> | ||
AB | ||
</Radio> | ||
<Radio value="lowercase" aria-label="Lowercase"> | ||
ab | ||
</Radio> | ||
<Radio value="capitalize" aria-label="Capitalize"> | ||
Ab | ||
</Radio> | ||
</RadioGroup> | ||
</FormGroup> | ||
); | ||
}; | ||
|
||
export const TypographyPanel = () => { | ||
const [ fontFamily, setFontFamily ] = useState(); | ||
const [ fontSize, setFontSize ] = useState(); | ||
const [ fontWeight, setFontWeight ] = useState(); | ||
const [ fontStyle, setFontStyle ] = useState(); | ||
const [ lineHeight, setLineHeight ] = useState(); | ||
const [ letterSpacing, setLetterSpacing ] = useState(); | ||
const [ textTransform, setTextTransform ] = useState(); | ||
|
||
return ( | ||
<> | ||
<div style={ { maxWidth: '280px' } }> | ||
<Panel> | ||
<ToolsPanel label="Typography Tools"> | ||
<ToolsPanelItem | ||
hasValue={ () => !! fontFamily } | ||
label="Font" | ||
onDeselect={ () => setFontFamily( undefined ) } | ||
isShownByDefault={ true } | ||
> | ||
<FontFamilyControl | ||
value={ fontFamily } | ||
onChange={ setFontFamily } | ||
fontFamilies={ fontFamilies } | ||
/> | ||
</ToolsPanelItem> | ||
|
||
<ToolsPanelItem | ||
hasValue={ () => !! fontSize } | ||
label="Size" | ||
onDeselect={ () => setFontSize( undefined ) } | ||
isShownByDefault={ true } | ||
> | ||
<FontSizePicker | ||
value={ fontSize } | ||
onChange={ setFontSize } | ||
fontSizes={ fontSizes } | ||
/> | ||
</ToolsPanelItem> | ||
|
||
<ToolsPanelItem | ||
hasValue={ () => !! fontStyle || !! fontWeight } | ||
label="Appearance" | ||
onDeselect={ () => { | ||
setFontStyle( undefined ); | ||
setFontWeight( undefined ); | ||
} } | ||
isShownByDefault={ true } | ||
> | ||
<FontAppearanceControl | ||
value={ { | ||
fontStyle, | ||
fontWeight, | ||
} } | ||
onChange={ ( { | ||
fontStyle: style, | ||
fontWeight: weight, | ||
} ) => { | ||
setFontStyle( style ); | ||
setFontWeight( weight ); | ||
} } | ||
/> | ||
</ToolsPanelItem> | ||
|
||
<ToolsPanelItem | ||
hasValue={ () => !! lineHeight } | ||
label="Line Height" | ||
onDeselect={ () => setLineHeight( undefined ) } | ||
isShownByDefault={ true } | ||
> | ||
<LineHeightControl | ||
value={ lineHeight } | ||
onChange={ setLineHeight } | ||
/> | ||
</ToolsPanelItem> | ||
|
||
<ToolsPanelItem | ||
hasValue={ () => !! letterSpacing } | ||
label="Letter Spacing" | ||
onDeselect={ () => setLetterSpacing( undefined ) } | ||
isShownByDefault={ true } | ||
> | ||
<LetterSpacingControl | ||
value={ letterSpacing } | ||
onChange={ setLetterSpacing } | ||
/> | ||
</ToolsPanelItem> | ||
|
||
<ToolsPanelItem | ||
hasValue={ () => !! textTransform } | ||
label="Letter Case" | ||
onDeselect={ () => setTextTransform( undefined ) } | ||
isShownByDefault={ true } | ||
> | ||
<LetterCaseControl | ||
onChange={ setTextTransform } | ||
checked={ textTransform } | ||
/> | ||
</ToolsPanelItem> | ||
</ToolsPanel> | ||
</Panel> | ||
</div> | ||
<div | ||
style={ { | ||
marginTop: '1rem', | ||
fontFamily, | ||
fontSize, | ||
fontStyle, | ||
fontWeight, | ||
lineHeight, | ||
letterSpacing, | ||
textTransform, | ||
} } | ||
> | ||
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do | ||
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut | ||
enim ad minim veniam, quis nostrud exercitation ullamco laboris | ||
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor | ||
in reprehenderit in voluptate velit esse cillum dolore eu fugiat | ||
nulla pariatur. Excepteur sint occaecat cupidatat non proident, | ||
sunt in culpa qui officia deserunt mollit anim id est laborum. | ||
</div> | ||
</> | ||
); | ||
}; |
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.
What is the reasoning behind picking these controls from
@wordpress/block-editor
, but pickingFontSizePicker
from@wordpress/components
?In general, for the purpose of this Storybook example, should we use components from
@wordpress/block-editor
or from@wordpress/components
?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.
I just imported the components used in the existing
TypographyPanel
for the most part.I don't think it really matters which things we use here (existing block-editor components or wp-component primitives) at least in this PR, as they are only placeholders right now. We'll be evaluating each piece on a case-by-case basis, and replace when necessary. As a starting point, I'm inclined toward having the "real world" block-editor components as a reference so we don't make assumptions based on static mockups only. (e.g. This has already surfaced a concern with the Letter Spacing mockup, which doesn't take units into account.)
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.
That makes sense to me. I was just curious about why we didn't also pick
FontSizePicker
from@wordpress/block-editor
.Makes sense, let's go with your approach!