This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utilities for consistent focus rings (#2067)
- Loading branch information
Showing
28 changed files
with
289 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const WithScreenshotArea = (story) => { | ||
return { | ||
template: ` | ||
<div | ||
class="screenshot-area" | ||
:style="{ display: 'inline-block', padding: '2rem' }" | ||
> | ||
<story /> | ||
</div>`, | ||
components: { story }, | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { Meta, Canvas, Story } from "@storybook/addon-docs" | ||
|
||
import { WithScreenshotArea } from "~~/.storybook/decorators/with-screenshot-area" | ||
|
||
<Meta title="Meta/Focus" decorators={[WithScreenshotArea]} /> | ||
|
||
export const GetTemplate = (irrelevantClassNames) => (args) => ({ | ||
template: ` | ||
<div | ||
class="h-30 w-30 flex items-center justify-center ${irrelevantClassNames}" | ||
:class="args.classNames" | ||
data-testid="focus-target" | ||
tabindex="0" | ||
> | ||
Focus on me | ||
</div>`, | ||
setup() { | ||
return { args } | ||
}, | ||
}) | ||
|
||
# Focus | ||
|
||
Focus styles are defined across two axes: thickness (slim or bold) and style | ||
(transparent or filled). However, there is no bold-transparent variant. | ||
|
||
The transparent style works best if the element has a border and no background | ||
color. On the other hand the filled style works with elements that have a | ||
background color and no border. | ||
|
||
Both the outer and inner strokes in filled border variants are box-shadows. | ||
|
||
## Slim transparent | ||
|
||
An outer stroke (colored) of 1.5px is applied to the component and the existing | ||
border is turned transparent. | ||
|
||
<Canvas> | ||
<Story name="Slim transparent" args={{ classNames: ["focus-slim-tx"] }}> | ||
{GetTemplate( | ||
"border border-dark-charcoal-40 hover:border-dark-charcoal" | ||
).bind({})} | ||
</Story> | ||
</Canvas> | ||
|
||
## Slim filled | ||
|
||
A colored outer stroke of 1.5px and a white inner stroke of 1.5px are both | ||
applied to the component. | ||
|
||
<Canvas> | ||
<Story name="Slim filled" args={{ classNames: ["focus-slim-filled"] }}> | ||
{GetTemplate("bg-pink text-white").bind({})} | ||
</Story> | ||
</Canvas> | ||
|
||
## Bold filled | ||
|
||
A colored outer stroke of 3.0px and a white inner stroke of 3.0px are both | ||
applied to the component. | ||
|
||
<Canvas> | ||
<Story name="Bold filled" args={{ classNames: ["focus-bold-filled"] }}> | ||
{GetTemplate("bg-yellow text-dark-charcoal").bind({})} | ||
</Story> | ||
</Canvas> | ||
|
||
## Colored | ||
|
||
The ring may be colored with a `-<color>` suffix after the appropriate class. If | ||
no color is set, the default is assumed to be pink. | ||
|
||
<Canvas> | ||
<Story | ||
name="Colored" | ||
args={{ classNames: ["focus-slim-tx-yellow"] }} | ||
parameters={{ backgrounds: { default: "Dark charcoal" } }} | ||
> | ||
{GetTemplate("bg-dark-charcoal text-white").bind({})} | ||
</Story> | ||
</Canvas> |
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 |
---|---|---|
|
@@ -59,6 +59,7 @@ const config: PlaywrightTestConfig = { | |
maxDiffPixelRatio: 0, | ||
}, | ||
}, | ||
retries: 2, | ||
} | ||
|
||
export default config |
Binary file modified
BIN
-398 Bytes
(99%)
...ilters-sidebar.spec.ts-snapshots/filters-sidebar-filters-selected-ltr-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-389 Bytes
(99%)
...ilters-sidebar.spec.ts-snapshots/filters-sidebar-filters-selected-rtl-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,23 @@ | ||
import { test, expect, Page, Locator } from "@playwright/test" | ||
|
||
const goTo = async (page: Page, slug: string) => { | ||
await page.goto(`/iframe.html?id=meta-focus--${slug}`) | ||
} | ||
|
||
const expectSnapshot = async (name: string, elem: Locator) => { | ||
expect(await elem.screenshot()).toMatchSnapshot({ name: `${name}.png` }) | ||
} | ||
|
||
const allSlugs = ["slim-transparent", "slim-filled", "bold-filled", "colored"] | ||
|
||
test.describe.configure({ mode: "parallel" }) | ||
|
||
test.describe("Focus", () => { | ||
for (const slug of allSlugs) { | ||
test(`focus-${slug}`, async ({ page }) => { | ||
await goTo(page, slug) | ||
await page.focus('[data-testid="focus-target"]') | ||
await expectSnapshot(`focus-${slug}`, page.locator(".screenshot-area")) | ||
}) | ||
} | ||
}) |
Binary file added
BIN
+2.11 KB
...storybook/visual-regression/focus.spec.ts-snapshots/focus-bold-filled-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.25 KB
test/storybook/visual-regression/focus.spec.ts-snapshots/focus-colored-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.29 KB
...storybook/visual-regression/focus.spec.ts-snapshots/focus-slim-filled-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.25 KB
...book/visual-regression/focus.spec.ts-snapshots/focus-slim-transparent-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.