Skip to content

Commit 495afea

Browse files
committed
feat: add circle variant to close button
1 parent 4057886 commit 495afea

File tree

3 files changed

+62
-20
lines changed

3 files changed

+62
-20
lines changed

src/components/close-button/close-button.component.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export default class CloseButton extends LitElement {
99

1010
private readonly _internals: ElementInternals;
1111

12+
@property({ reflect: true })
13+
variant: 'square' | 'circle' = 'square';
14+
1215
/**
1316
* Whether or not the button is disabled.
1417
*/
@@ -43,14 +46,7 @@ export default class CloseButton extends LitElement {
4346
tabindex=${this.disabled ? '-1' : '0'}
4447
@click="${this.handleClick}"
4548
>
46-
<svg
47-
version="1.1"
48-
viewBox="0 0 16 16"
49-
width="16"
50-
height="16"
51-
fill="currentColor"
52-
aria-hidden="true"
53-
>
49+
<svg viewBox="0 0 16 16" width="20" height="20" fill="currentColor" aria-hidden="true">
5450
<path
5551
d="M3.72 3.72a.75.75 0 0 1 1.06 0L8 6.94l3.22-3.22a.749.749 0 0 1 1.275.326.749.749 0 0 1-.215.734L9.06 8l3.22 3.22a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215L8 9.06l-3.22 3.22a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042L6.94 8 3.72 4.78a.75.75 0 0 1 0-1.06Z"
5652
></path>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { Meta, StoryObj } from '@storybook/web-components';
2+
import { html } from 'lit';
3+
import './close-button';
4+
5+
type Story = StoryObj;
6+
7+
const meta: Meta = {
8+
title: 'Core/zx-close-button',
9+
argTypes: {
10+
variant: {
11+
control: 'select',
12+
options: ['square', 'circle'],
13+
},
14+
},
15+
args: {
16+
variant: 'square',
17+
},
18+
};
19+
20+
export const Sandbox: Story = {
21+
render: args => html`<zx-close-button variant="${args.variant}"></zx-close-button>`,
22+
};
23+
24+
export const Showcase = () => `
25+
<div class="grid gap-8">
26+
<zx-close-button variant="square"></zx-close-button>
27+
<zx-close-button variant="circle"></zx-close-button>
28+
</div>
29+
`;
30+
31+
export default meta;

src/components/close-button/close-button.styles.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ import { css } from 'lit';
22

33
export default css`
44
:host {
5+
--button-size: 32px;
6+
--button-radius: 4px;
7+
--button-color: #374151; /* gray.700 */
8+
--button-bg: transparent;
9+
--button-bg-hover: #f3f4f6; /* gray.100 */
10+
511
display: inline-flex;
612
align-items: center;
713
justify-items: center;
8-
/*
9-
https://www.benjystanton.co.uk/blog/accessible-close-buttons/
10-
Accessibility: the overall size of should be at least 44 pixels in height and width
11-
*/
12-
padding: 8px;
13-
14-
--border-radius: 4px;
15-
--bg-hover: #f5f5f5;
1614
}
1715
1816
:host([disabled]) button {
@@ -24,19 +22,36 @@ export default css`
2422
all: unset;
2523
display: grid;
2624
place-items: center;
27-
width: 32px;
28-
height: 32px;
2925
margin: auto;
30-
border-radius: var(--border-radius);
26+
width: var(--button-size);
27+
height: var(--button-size);
28+
background-color: var(--button-bg);
29+
border-radius: var(--button-radius);
30+
color: var(--button-color);
3131
cursor: pointer;
3232
}
3333
3434
button:hover {
35-
background: var(--bg-hover);
35+
background-color: var(--button-bg-hover);
3636
}
3737
3838
button:focus-visible {
3939
outline: 2px solid #111827;
4040
outline-offset: -2px;
4141
}
42+
43+
:host([variant='square']) {
44+
/*
45+
https://www.benjystanton.co.uk/blog/accessible-close-buttons/
46+
Accessibility: the overall size of should be at least 44 pixels in height and width
47+
*/
48+
padding: 8px;
49+
}
50+
51+
:host([variant='circle']) {
52+
--button-radius: 9999px;
53+
--button-size: 44px;
54+
--button-bg: #f3f4f6; /* gray.100 */
55+
--button-bg-hover: #e5e7eb; /* gray.200 */
56+
}
4257
`;

0 commit comments

Comments
 (0)