-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Button: Revise documentation (#66617)
* Button: Auto-generate README * Add additional mdx file * Fixup to prevent merging consecutive lists * Add FigmaEmbed component * Update best-practices.mdx - added content - added embeds * Update best-practices.mdx Removed sample Figma embed link * Update best-practices.mdx - Fixed Figma links * Fixup * Fix iframe titles * Replace sizes section * Move variant description to story description? * Move variant descriptions to main docs --------- Co-authored-by: mirka <[email protected]> Co-authored-by: auareyou <[email protected]> Co-authored-by: jameskoster <[email protected]> Co-authored-by: jasmussen <[email protected]> Co-authored-by: tyxla <[email protected]> Co-authored-by: ciampo <[email protected]>
- Loading branch information
1 parent
84f29ea
commit 2eec579
Showing
8 changed files
with
221 additions
and
224 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,5 @@ | ||
{ | ||
"$schema": "../../schemas/docs-manifest.json", | ||
"displayName": "Button", | ||
"filePath": "./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,31 @@ | ||
import { Meta } from '@storybook/blocks'; | ||
|
||
<Meta title="Components/Actions/Button/Best Practices" /> | ||
|
||
# Button | ||
|
||
## Usage | ||
Buttons indicate available actions and allow user interaction within the interface. As key elements in the WordPress UI, they appear in toolbars, modals, and forms. Default buttons support most actions, while primary buttons emphasize the main action in a view. Secondary buttons pair as secondary actions next to a primary action. | ||
|
||
Each layout contains one prominently placed, high-emphasis button. If you need multiple buttons, use one primary button for the main action, secondary for the rest of the actions and tertiary sparingly when an action needs to not stand out at all. | ||
|
||
### Sizes | ||
|
||
- `'default'`: For normal text-label buttons, unless it is a toggle button. | ||
- `'compact'`: For toggle buttons, icon buttons, and buttons when used in context of either. | ||
- `'small'`: For icon buttons associated with more advanced or auxiliary features. | ||
|
||
## Best practices | ||
|
||
- Label buttons to show that a click or tap initiates an action. | ||
- Use established color conventions; for example, reserve red buttons for irreversible or dangerous actions. | ||
- Avoid crowding the screen with multiple calls to action, which confuses users. | ||
- Keep button locations consistent across the interface. | ||
|
||
## Content guidelines | ||
|
||
Buttons should be clear and predictable, showing users what will happen when clicked. Make labels reflect actions accurately to avoid confusion. | ||
|
||
Start button text with a strong action verb and include a noun to specify the change, except for common actions like Save, Close, Cancel, or OK. | ||
|
||
For other actions, use a `{verb}+{noun}` format for context. Keep button text brief and remove unnecessary words like "the," "an," or "a" for easy scanning. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
|
||
// See https://www.figma.com/developers/embed#embed-a-figma-file | ||
const CONFIG = { | ||
'embed-host': 'wordpress-storybook', | ||
footer: false, | ||
'page-selector': false, | ||
'viewport-controls': true, | ||
}; | ||
|
||
/** | ||
* Embed Figma links in the Storybook. | ||
* | ||
* @param {Object} props | ||
* @param {string} props.url - Figma URL to embed. | ||
* @param {string} props.title - Accessible title for the iframe. | ||
*/ | ||
function FigmaEmbed( { url, title, ...props } ) { | ||
const urlObj = new URL( url ); | ||
|
||
const queryParams = new URLSearchParams( urlObj.search ); | ||
Object.entries( CONFIG ).forEach( ( [ key, value ] ) => { | ||
queryParams.set( key, value ); | ||
} ); | ||
urlObj.search = queryParams.toString(); | ||
|
||
urlObj.hostname = urlObj.hostname.replace( | ||
'www.figma.com', | ||
'embed.figma.com' | ||
); | ||
|
||
const normalizedUrl = urlObj.toString(); | ||
|
||
return ( | ||
<iframe | ||
title={ title } | ||
src={ normalizedUrl } | ||
className="wp-storybook-figma-embed" | ||
{ ...props } | ||
/> | ||
); | ||
} | ||
|
||
export default FigmaEmbed; |
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,4 @@ | ||
.wp-storybook-figma-embed { | ||
width: 100%; | ||
border: none; | ||
} |
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