generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 204
chore: Themeable icon stroke width #4079
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
Open
at-susie
wants to merge
14
commits into
main
Choose a base branch
from
feat/themeable-icon-stroke
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a1f0376
chore: Add icon stroke-width tokens
at-susie 639dc0e
Revert "chore: Add icon stroke-width tokens"
at-susie d7ef106
chore: Update icon stroke width tokens
at-susie 87d7d8e
chore: Update tokens and add example page
at-susie 15bf4d8
chore: Update snapshot
at-susie c036635
chore: Fix a11y issue
at-susie 4c7c893
chore: Refine metadata and remove unnecessary tokens
at-susie 665363e
chore: Update snapshot
at-susie 5b9a983
chore: Update integration stest snapshot
at-susie 36d247e
chore: Fix scale bug for small size variant
at-susie 30e2269
chore: Fix bug in the example page
at-susie a5ff3a1
Merge branch 'main' into feat/themeable-icon-stroke
at-susie b770066
chore: Improve example page
at-susie a7d68ec
chore: Small example page adjustment for bug bash
at-susie 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,335 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import React, { useLayoutEffect, useState } from 'react'; | ||
|
|
||
| import { | ||
| Alert, | ||
| Box, | ||
| Button, | ||
| Flashbar, | ||
| FormField, | ||
| IconProvider, | ||
| Input, | ||
| KeyValuePairs, | ||
| Link, | ||
| Select, | ||
| SelectProps, | ||
| SpaceBetween, | ||
| StatusIndicator, | ||
| } from '~components'; | ||
| import Icon, { IconProps } from '~components/icon'; | ||
| import icons from '~components/icon/generated/icons'; | ||
| import { applyTheme, Theme } from '~components/theming'; | ||
|
|
||
| import ScreenshotArea from '../utils/screenshot-area'; | ||
|
|
||
| import styles from '../icon/icons-list.scss'; | ||
|
|
||
| export default function () { | ||
| const [themed, setThemed] = useState<boolean>(false); | ||
| const [strokeSmall, setStrokeSmall] = useState<string>('1'); | ||
| const [strokeNormal, setStrokeNormal] = useState<string>('1'); | ||
| const [strokeMedium, setStrokeMedium] = useState<string>('1'); | ||
| const [strokeBig, setStrokeBig] = useState<string>('1.5'); | ||
| const [strokeLarge, setStrokeLarge] = useState<string>('2'); | ||
| const [selectedOption, setSelectedOption] = useState<SelectProps.Option>({ label: 'Option 1', value: '1' }); | ||
|
|
||
| // Reload page once after initial load to fix theme application | ||
| useLayoutEffect(() => { | ||
| const hasReloaded = sessionStorage.getItem('themed-stroke-width-reloaded'); | ||
| if (!hasReloaded) { | ||
| sessionStorage.setItem('themed-stroke-width-reloaded', 'true'); | ||
| window.location.reload(); | ||
| } | ||
| }, []); | ||
|
|
||
| useLayoutEffect(() => { | ||
| let reset: () => void = () => {}; | ||
| if (themed) { | ||
| const theme: Theme = { | ||
| tokens: { | ||
| borderWidthIconSmall: strokeSmall ? `${strokeSmall}px` : '1px', | ||
| borderWidthIconNormal: strokeNormal ? `${strokeNormal}px` : '1px', | ||
| borderWidthIconMedium: strokeMedium ? `${strokeMedium}px` : '1px', | ||
| borderWidthIconBig: strokeBig ? `${strokeBig}px` : '1.5px', | ||
| borderWidthIconLarge: strokeLarge ? `${strokeLarge}px` : '2px', | ||
| }, | ||
| }; | ||
|
|
||
| const result = applyTheme({ | ||
| theme, | ||
| baseThemeId: 'visual-refresh', | ||
| }); | ||
| reset = result.reset; | ||
| } | ||
| return reset; | ||
| }, [themed, strokeSmall, strokeNormal, strokeMedium, strokeBig, strokeLarge]); | ||
|
|
||
| return ( | ||
| <div style={{ padding: 15 }}> | ||
| <h1>Themed icon stroke width</h1> | ||
| <SpaceBetween size="m" direction="vertical"> | ||
| <label> | ||
| <input | ||
| type="checkbox" | ||
| data-testid="apply-theme" | ||
| checked={themed} | ||
| onChange={evt => setThemed(evt.currentTarget.checked)} | ||
| /> | ||
| <span style={{ marginInlineStart: 5 }}>Apply custom stroke width themes</span> | ||
| </label> | ||
|
|
||
| <div style={{ display: 'grid', gridTemplateColumns: 'repeat(5, 1fr)', gap: '10px', maxWidth: '800px' }}> | ||
| <FormField label="Small (16px)" description="Default: 2px"> | ||
| <Input | ||
| type="number" | ||
| value={strokeSmall} | ||
| onChange={evt => { | ||
| const numValue = parseFloat(evt.detail.value); | ||
| if (!isNaN(numValue) && numValue >= 1) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe to much but we could add here min/max constraints |
||
| setStrokeSmall(evt.detail.value); | ||
| } else if (evt.detail.value === '') { | ||
| setStrokeSmall(evt.detail.value); | ||
| } | ||
| }} | ||
| placeholder="1px" | ||
| step={0.5} | ||
| inputMode="decimal" | ||
| /> | ||
| </FormField> | ||
|
|
||
| <FormField label="Normal (16px)" description="Default: 2px"> | ||
| <Input | ||
| type="number" | ||
| value={strokeNormal} | ||
| onChange={evt => { | ||
| const numValue = parseFloat(evt.detail.value); | ||
| if (!isNaN(numValue) && numValue >= 1) { | ||
| setStrokeNormal(evt.detail.value); | ||
| } else if (evt.detail.value === '') { | ||
| setStrokeNormal(evt.detail.value); | ||
| } | ||
| }} | ||
| placeholder="1px" | ||
| step={0.5} | ||
| inputMode="decimal" | ||
| /> | ||
| </FormField> | ||
|
|
||
| <FormField label="Medium (20px)" description="Default: 2px"> | ||
| <Input | ||
| type="number" | ||
| value={strokeMedium} | ||
| onChange={evt => { | ||
| const numValue = parseFloat(evt.detail.value); | ||
| if (!isNaN(numValue) && numValue >= 1) { | ||
| setStrokeMedium(evt.detail.value); | ||
| } else if (evt.detail.value === '') { | ||
| setStrokeMedium(evt.detail.value); | ||
| } | ||
| }} | ||
| placeholder="1px" | ||
| step={0.5} | ||
| inputMode="decimal" | ||
| /> | ||
| </FormField> | ||
|
|
||
| <FormField label="Big (32px)" description="Default: 3px"> | ||
| <Input | ||
| type="number" | ||
| value={strokeBig} | ||
| onChange={evt => { | ||
| const numValue = parseFloat(evt.detail.value); | ||
| if (!isNaN(numValue) && numValue >= 1) { | ||
| setStrokeBig(evt.detail.value); | ||
| } else if (evt.detail.value === '') { | ||
| setStrokeBig(evt.detail.value); | ||
| } | ||
| }} | ||
| placeholder="1.5px" | ||
| step={0.5} | ||
| inputMode="decimal" | ||
| /> | ||
| </FormField> | ||
|
|
||
| <FormField label="Large (48px)" description="Default: 4px"> | ||
| <Input | ||
| type="number" | ||
| value={strokeLarge} | ||
| onChange={evt => { | ||
| const numValue = parseFloat(evt.detail.value); | ||
| if (!isNaN(numValue) && numValue >= 1) { | ||
| setStrokeLarge(evt.detail.value); | ||
| } else if (evt.detail.value === '') { | ||
| setStrokeLarge(evt.detail.value); | ||
| } | ||
| }} | ||
| placeholder="2px" | ||
| step={0.5} | ||
| inputMode="decimal" | ||
| /> | ||
| </FormField> | ||
| </div> | ||
| </SpaceBetween> | ||
|
|
||
| <ScreenshotArea | ||
| key={`themed-${themed}-${strokeSmall}-${strokeNormal}-${strokeMedium}-${strokeBig}-${strokeLarge}`} | ||
| > | ||
| <SpaceBetween size="xl"> | ||
| <Box variant="h2" padding={{ top: 'l' }}> | ||
| Icon sizes | ||
| </Box> | ||
|
|
||
| <SpaceBetween size="xs"> | ||
| <Box variant="h3">Small (16px with shorter wrapper size)</Box> | ||
| <div className={styles.wrapper}> | ||
| {Object.keys(icons).map(icon => ( | ||
| <Icon key={icon} name={icon as IconProps['name']} variant="normal" size="small" /> | ||
| ))} | ||
| </div> | ||
| </SpaceBetween> | ||
|
|
||
| <SpaceBetween size="xs"> | ||
| <Box variant="h3">Normal (16px)</Box> | ||
| <div className={styles.wrapper}> | ||
| {Object.keys(icons).map(icon => ( | ||
| <Icon key={icon} name={icon as IconProps['name']} variant="normal" size="normal" /> | ||
| ))} | ||
| </div> | ||
| </SpaceBetween> | ||
|
|
||
| <SpaceBetween size="xs"> | ||
| <Box variant="h3">Medium (20px)</Box> | ||
| <div className={styles.wrapper}> | ||
| {Object.keys(icons).map(icon => ( | ||
| <Icon key={icon} name={icon as IconProps['name']} variant="normal" size="medium" /> | ||
| ))} | ||
| </div> | ||
| </SpaceBetween> | ||
|
|
||
| <SpaceBetween size="xs"> | ||
| <Box variant="h3">Big (32px)</Box> | ||
| <div className={styles.wrapper}> | ||
| {Object.keys(icons).map(icon => ( | ||
| <Icon key={icon} name={icon as IconProps['name']} variant="normal" size="big" /> | ||
| ))} | ||
| </div> | ||
| </SpaceBetween> | ||
|
|
||
| <SpaceBetween size="xs"> | ||
| <Box variant="h3">Large (48px)</Box> | ||
| <div className={styles.wrapper}> | ||
| {Object.keys(icons).map(icon => ( | ||
| <Icon key={icon} name={icon as IconProps['name']} variant="normal" size="large" /> | ||
| ))} | ||
| </div> | ||
| </SpaceBetween> | ||
|
|
||
| <Box variant="h2" padding={{ top: 'l' }}> | ||
| Inline Context Examples | ||
| </Box> | ||
|
|
||
| <SpaceBetween size="m"> | ||
| <div> | ||
| <Button iconName="call" variant="primary"> | ||
| Button | ||
| </Button> | ||
| </div> | ||
|
|
||
| <div> | ||
| <Link external={true} href="https://example.com/" variant="primary"> | ||
| Learn more | ||
| </Link> | ||
| </div> | ||
|
|
||
| <div style={{ maxWidth: '300px' }}> | ||
| <Select | ||
| selectedOption={selectedOption} | ||
| onChange={({ detail }) => setSelectedOption(detail.selectedOption)} | ||
| options={[ | ||
| { label: 'Option 1', value: '1', iconName: 'settings' }, | ||
| { label: 'Option 2', value: '2', iconName: 'unlocked' }, | ||
| { label: 'Option 3', value: '3', iconName: 'share' }, | ||
| ]} | ||
| /> | ||
| </div> | ||
|
|
||
| <div style={{ maxWidth: '300px' }}> | ||
| <FormField | ||
| label="Email address" | ||
| errorText="Please enter a valid email address" | ||
| constraintText="Use your company email" | ||
| > | ||
| <Input value="invalid-email" type="email" readOnly={true} /> | ||
| </FormField> | ||
| </div> | ||
|
|
||
| <SpaceBetween size="xs"> | ||
| <StatusIndicator type="error">Error</StatusIndicator> | ||
| <StatusIndicator type="success">Success</StatusIndicator> | ||
| <StatusIndicator type="warning">Warning</StatusIndicator> | ||
| <StatusIndicator type="info">Info</StatusIndicator> | ||
| </SpaceBetween> | ||
| <IconProvider | ||
| icons={{ | ||
| 'status-positive': ( | ||
| <svg viewBox="0 0 16 18" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
| <path d="M5 9L7 11L11 7" /> | ||
| <path d="M8 2C6.29 3.53 4.13 4.32 2 4.48V7.96C2 10.01 2.76 11.84 3.71 13.1C4.63 14.32 6.03 15.31 8 16C9.97 15.31 11.37 14.32 12.29 13.1C13.3935 11.6128 13.9926 9.81183 14 7.96V4.48C11.87 4.32 9.71 3.52 8 2Z" /> | ||
| </svg> | ||
| ), | ||
| }} | ||
| > | ||
| <SpaceBetween size="xs"> | ||
| <Box variant="h2" padding={{ top: 'l' }}> | ||
| Custom icon using icon-provider component | ||
| </Box> | ||
| <KeyValuePairs | ||
| columns={1} | ||
| items={[ | ||
| { | ||
| label: 'Custom icon in a status indicator', | ||
| value: <StatusIndicator type="success">Two-factor authentication enabled</StatusIndicator>, | ||
| }, | ||
| { | ||
| label: 'Custom icon in an alert', | ||
| value: ( | ||
| <Alert type="success" statusIconAriaLabel="Success"> | ||
| Two-factor authentication enabled successfully. | ||
| </Alert> | ||
| ), | ||
| }, | ||
| { | ||
| label: 'Custom icon in a flashbar', | ||
| value: ( | ||
| <Flashbar | ||
| items={[ | ||
| { | ||
| type: 'success', | ||
| content: 'Two-factor authentication enabled successfully.', | ||
| statusIconAriaLabel: 'Success', | ||
| }, | ||
| ]} | ||
| /> | ||
| ), | ||
| }, | ||
| ]} | ||
| /> | ||
| </SpaceBetween> | ||
| </IconProvider> | ||
| <p style={{ lineHeight: '28px', fontSize: '18px' }}> | ||
| Lorem ipsum dolor sit amet,{' '} | ||
| <Link external={true} href="#"> | ||
| Learn more | ||
| </Link>{' '} | ||
| consectetur adipiscing 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 | ||
| </p> | ||
| </SpaceBetween> | ||
| </SpaceBetween> | ||
| </ScreenshotArea> | ||
| </div> | ||
| ); | ||
| } | ||
Oops, something went wrong.
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.
Does values are not aligned with the default values like 2px, 3px and 4px. Is this on purpose?
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.
Good call. I will refine the UIs overall in the example page