Skip to content

Commit 9448bf3

Browse files
committed
Dark theme updates to Button component
1 parent c0d4441 commit 9448bf3

8 files changed

Lines changed: 197 additions & 66 deletions

File tree

‎_TODO.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ Generate cover images for the skills and technologies tags pages
175175

176176
- add "cel" language to code blocks
177177

178+
- The code language is in teh tab order and getting focus-visible
179+
178180
## Callout Issues
179181

180182
- When adding backticks in a callout, it gets the standard grey background for a code block in light theme. But it should get an offset of the callout color, like "info-offset".

‎src/components/Button/server/__tests__/index.spec.ts‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,6 @@ describe('Button server helpers', () => {
3939
expect(classList['custom']).toBe(true)
4040
expect(classList['extra-class']).toBe(true)
4141
})
42-
43-
it('supports the spotlight variant', () => {
44-
const classList = buildButtonClassList({
45-
variant: 'spotlight',
46-
})
47-
48-
expect(classList).toMatchObject<ClassList>({
49-
'bg-spotlight': true,
50-
'hover:bg-spotlight-offset': true,
51-
'focus-visible:bg-spotlight-offset': true,
52-
'active:bg-spotlight-offset': true,
53-
})
54-
})
5542
})
5643

5744
describe('resolveAriaLabel', () => {

‎src/components/Button/server/index.ts‎

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
export type ButtonVariant =
2+
| 'danger'
3+
| 'note'
24
| 'primary'
35
| 'secondary'
46
| 'twitter'
57
| 'success'
6-
| 'success-offset'
8+
| 'info'
79
| 'warning'
8-
| 'spotlight'
910
| 'icon'
1011
export type ButtonSize = 'small' | 'medium' | 'large'
1112
export type ButtonType = 'button' | 'submit' | 'reset'
@@ -43,11 +44,13 @@ function addClassNames(classList: ClassList, classNames: string) {
4344
const baseButtonClasses =
4445
'inline-flex items-center justify-center text-center align-middle whitespace-nowrap select-none ' +
4546
'no-underline hover:no-underline focus:no-underline focus-visible:no-underline decoration-transparent ' +
46-
'focus:outline-none focus-visible:outline-2 focus-visible:outline-spotlight focus-visible:outline-offset-2 focus-visible:rounded-none ' +
47+
'relative focus-visible:outline-none ' +
48+
"after:pointer-events-none after:absolute after:content-[''] after:inset-0 after:rounded-none after:border-2 after:border-transparent after:opacity-0 after:transition-opacity after:duration-150 after:ease-out " +
49+
'focus-visible:after:opacity-100 focus-visible:after:[inset:-6px] focus-visible:after:border-spotlight ' +
4750
'border-2 border-solid border-transparent rounded-md ' +
4851
'font-bold uppercase tracking-[0.08em] ' +
4952
'text-sm leading-5 ' +
50-
'transition-[color,background-color,border-color,box-shadow,transform] duration-200 ease-in-out ' +
53+
'transition-[color,background-color,border-color] duration-200 ease-in-out ' +
5154
'disabled:cursor-not-allowed disabled:opacity-[0.65] disabled:pointer-events-none ' +
5255
'aria-disabled:cursor-not-allowed aria-disabled:opacity-[0.65] aria-disabled:pointer-events-none'
5356

@@ -61,43 +64,52 @@ const sizeClasses: Record<ButtonSize, string> = {
6164
}
6265

6366
const variantClasses: Record<ButtonVariant, string> = {
67+
danger:
68+
'bg-danger text-white ' +
69+
'hover:bg-danger-offset ' +
70+
'focus-visible:bg-danger-offset ' +
71+
'active:bg-danger-offset',
72+
icon:
73+
'aspect-square bg-transparent text-white p-2 ' +
74+
'hover:bg-page-offset hover:text-primary ' +
75+
'focus-visible:bg-page-offset focus-visible:text-primary ' +
76+
'active:bg-page-offset',
77+
info:
78+
'bg-info text-white ' +
79+
'hover:bg-info-offset ' +
80+
'focus-visible:bg-info-offset ' +
81+
'active:bg-info-offset',
82+
note:
83+
'bg-note text-white ' +
84+
'hover:bg-note-offset ' +
85+
'focus-visible:bg-note-offset ' +
86+
'active:bg-note-offset',
6487
primary:
65-
'bg-primary text-content ' +
66-
'hover:bg-primary-offset hover:[box-shadow:var(--shadow-hover)] ' +
67-
'focus-visible:bg-primary-offset focus-visible:[box-shadow:var(--shadow-hover)] ' +
68-
'active:bg-primary-offset active:[box-shadow:var(--shadow-active)]',
88+
'bg-primary text-primary-inverse ' +
89+
'hover:bg-primary-offset ' +
90+
'focus-visible:bg-primary-offset ' +
91+
'active:bg-primary-offset',
6992
secondary:
70-
'bg-secondary text-content ' +
71-
'hover:bg-secondary-offset hover:[box-shadow:var(--shadow-hover)] ' +
72-
'focus-visible:bg-secondary-offset focus-visible:[box-shadow:var(--shadow-hover)] ' +
73-
'active:bg-secondary-offset active:[box-shadow:var(--shadow-active)]',
74-
twitter: 'bg-x border-x text-content hover:bg-transparent hover:text-x focus-visible:bg-transparent focus-visible:text-x',
93+
'bg-secondary text-secondary-inverse ' +
94+
'hover:bg-secondary-offset ' +
95+
'focus-visible:bg-secondary-offset ' +
96+
'active:bg-secondary-offset',
7597
success:
7698
'bg-success text-white ' +
77-
'hover:bg-success-offset hover:[box-shadow:var(--shadow-hover)] ' +
78-
'focus-visible:bg-success-offset focus-visible:[box-shadow:var(--shadow-hover)] ' +
79-
'active:bg-success-offset active:[box-shadow:var(--shadow-active)]',
80-
'success-offset':
81-
'bg-success-offset text-content-inverse ' +
82-
'hover:bg-success hover:[box-shadow:var(--shadow-hover)] ' +
83-
'focus-visible:bg-success focus-visible:[box-shadow:var(--shadow-hover)] ' +
84-
'active:bg-success active:[box-shadow:var(--shadow-active)]',
99+
'hover:bg-success-offset ' +
100+
'focus-visible:bg-success-offset ' +
101+
'active:bg-success-offset',
102+
twitter:
103+
'bg-x border-x text-white ' +
104+
'hover:bg-transparent hover:text-x ' +
105+
'focus-visible:bg-transparent ' +
106+
'focus-visible:text-x',
85107
warning:
86-
'bg-warning text-content ' +
87-
'hover:bg-warning-offset hover:[box-shadow:var(--shadow-hover)] ' +
88-
'focus-visible:bg-warning-offset focus-visible:[box-shadow:var(--shadow-hover)] ' +
89-
'active:bg-warning-offset active:[box-shadow:var(--shadow-active)]',
90-
spotlight:
91-
'bg-spotlight text-black ' +
92-
'hover:bg-spotlight-offset hover:[box-shadow:var(--shadow-hover)] ' +
93-
'focus-visible:bg-spotlight-offset focus-visible:[box-shadow:var(--shadow-hover)] ' +
94-
'active:bg-spotlight-offset active:[box-shadow:var(--shadow-active)]',
95-
icon:
96-
'aspect-square bg-transparent text-content p-2 ![box-shadow:none] ' +
97-
'hover:bg-page-offset hover:text-primary ' +
98-
'focus-visible:bg-page-offset focus-visible:text-primary ' +
99-
'active:bg-page-offset',
100-
}
108+
'bg-warning-offset text-white ' +
109+
'hover:bg-warning ' +
110+
'focus-visible:bg-warning ' +
111+
'active:bg-warning',
112+
}
101113

102114
export interface ButtonClassOptions {
103115
variant?: ButtonVariant
@@ -111,10 +123,15 @@ export function buildButtonClassList({
111123
additionalClasses,
112124
}: ButtonClassOptions) {
113125
const classList: ClassList = {}
126+
const selectedVariant = variant as string
127+
128+
if (!(selectedVariant in variantClasses)) {
129+
throw new Error(`Button: unsupported variant '${selectedVariant}'`)
130+
}
114131

115132
addClassNames(classList, baseButtonClasses)
116133
addClassNames(classList, sizeClasses[size])
117-
addClassNames(classList, variantClasses[variant])
134+
addClassNames(classList, variantClasses[selectedVariant as ButtonVariant])
118135

119136
if (additionalClasses?.trim()) {
120137
addClassNames(classList, additionalClasses)

‎src/components/CallToAction/Download/index.astro‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const downloadUrl = `/downloads/${normalizedResource}`
109109
<div class="space-y-3">
110110
<Button
111111
href={downloadUrl}
112-
variant="success-offset"
112+
variant="success"
113113
class="w-full gap-2 px-6 py-3 text-content-inverse"
114114
>
115115
<Icon

‎src/components/List/layouts/NumberedWithBackgroundList.astro‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ const emClass = ["text-content font-semibold not-italic", classes?.em]
2020

2121
<ol class:list={olClass}>
2222
{
23-
items.map((item) => (
23+
items.map((item, index) => (
2424
<li class:list={liClass}>
25-
<span class="mt-2 shrink-0 w-8 h-8 bg-primary text-white rounded-full flex items-center justify-center text-sm font-bold">1</span>
25+
<span class="mt-2 shrink-0 w-8 h-8 bg-primary text-content-inverse rounded-full flex items-center justify-center text-sm font-bold">{index + 1}</span>
2626
<div class="pt-1">
2727
<em class:list={emClass}>{item.lead}</em>
2828
<div>{item.text}</div>

‎src/components/Pages/MyData/index.astro‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2+
import Button from '@components/Button/index.astro'
23
import Icon from '@components/Icon/index.astro'
34
import List from '@components/List/index.astro'
45
@@ -101,12 +102,12 @@ const { content } = Astro.props
101102
/>
102103
</div>
103104

104-
<button
105+
<Button
105106
type="submit"
106-
class="inline-flex items-center justify-center rounded-xl px-6 py-3 bg-spotlight-offset hover:bg-spotlight text-white font-semibold transition-colors mt-8 focus-visible:outline-2 focus-visible:outline-spotlight focus-visible:outline-offset-2 focus-visible:rounded-none"
107-
>
108-
{content.accessData.buttonText}
109-
</button>
107+
variant="info"
108+
class="mt-8 px-6 py-3"
109+
text={content.accessData.buttonText}
110+
/>
110111

111112
<div
112113
id="access-message"
@@ -163,12 +164,12 @@ const { content } = Astro.props
163164
<span class="mt-0.5">{content.deleteData.confirmText}</span>
164165
</label>
165166

166-
<button
167+
<Button
167168
type="submit"
168-
class="inline-flex items-center justify-center rounded-xl px-6 py-3 bg-danger-offset text-white font-semibold hover:bg-danger transition-colors focus-visible:outline-2 focus-visible:outline-spotlight focus-visible:outline-offset-2 focus-visible:rounded-none"
169-
>
170-
{content.deleteData.buttonText}
171-
</button>
169+
variant="warning"
170+
class="px-6 py-3"
171+
text={content.deleteData.buttonText}
172+
/>
172173

173174
<div
174175
id="delete-message"
@@ -183,7 +184,9 @@ const { content } = Astro.props
183184
</div>
184185

185186
<section class="border border-trim rounded-2xl p-6" aria-labelledby="my-data-next-title">
186-
<h2 id="my-data-next-title" class="text-page-inverse text-xl font-semibold mb-4">{content.next.heading}</h2>
187+
<h2 id="my-data-next-title" class="text-page-inverse text-xl font-semibold mb-4">
188+
{content.next.heading}
189+
</h2>
187190
<List variant="numbered-with-background-list" items={content.next.items} />
188191
</section>
189192
</div>

‎src/content/articles/demo/index.mdx‎

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,127 @@ Should compile to the following HTML:
277277

278278
**This text is _extremely_ important**
279279

280-
## Calendar
280+
## Buttons
281+
282+
Each color variant is shown in an example below. Sizes are 'small', 'medium', 'large' with 'medium' the default. Types are 'button', 'submit', and 'reset' and are passed directly to the `<button>` element as its type prop.
283+
284+
```markdown
285+
<Button
286+
type="submit"
287+
variant="danger"
288+
class="px-6 py-3 mb-4"
289+
text="Go Home"
290+
/>
291+
```
292+
293+
<Button
294+
type="submit"
295+
variant="danger"
296+
class="px-6 py-3 mb-4"
297+
text="Go Home"
298+
/>
299+
300+
```markdown
301+
<Button
302+
type="button"
303+
variant="info"
304+
class="px-6 py-3 mb-4"
305+
text="Go Home"
306+
/>
307+
```
281308

282-
import Calendar from '@components/Calendar/index.astro'
309+
<Button
310+
type="button"
311+
variant="info"
312+
class="px-6 py-3 mb-4"
313+
text="Go Home"
314+
/>
315+
316+
```markdown
317+
<Button
318+
type="reset"
319+
variant="note"
320+
class="px-6 py-3 mb-4"
321+
text="Go Home"
322+
/>
323+
```
324+
325+
<Button
326+
type="reset"
327+
variant="note"
328+
class="px-6 py-3 mb-4"
329+
text="Go Home"
330+
/>
331+
332+
```markdown
333+
<Button
334+
type="submit"
335+
variant="primary"
336+
size="small"
337+
class="px-6 py-3 mb-4"
338+
text="Go Home"
339+
/>
340+
```
341+
342+
<Button
343+
type="submit"
344+
variant="primary"
345+
size="small"
346+
class="px-6 py-3 mb-4"
347+
text="Go Home"
348+
/>
349+
350+
```markdown
351+
<Button
352+
type="submit"
353+
variant="secondary"
354+
size="large"
355+
class="px-6 py-3" mb-4
356+
text="Go Home"
357+
/>
358+
```
359+
360+
<Button
361+
type="submit"
362+
variant="secondary"
363+
size="large"
364+
class="px-6 py-3 mb-4"
365+
text="Go Home"
366+
/>
367+
368+
```markdown
369+
<Button
370+
type="submit"
371+
variant="success"
372+
class="px-6 py-3 mb-4"
373+
text="Go Home"
374+
/>
375+
```
376+
377+
<Button
378+
type="submit"
379+
variant="success"
380+
class="px-6 py-3 mb-4"
381+
text="Go Home"
382+
/>
383+
384+
```markdown
385+
<Button
386+
type="submit"
387+
variant="warning"
388+
class="px-6 py-3 mb-4"
389+
text="Go Home"
390+
/>
391+
```
392+
393+
<Button
394+
type="submit"
395+
variant="warning"
396+
class="px-6 py-3 mb-4"
397+
text="Go Home"
398+
/>
399+
400+
## Calendar
283401

284402
```markdown
285403
<Calendar />

‎src/layouts/MarkdownLayout.astro‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import Toc from '@components/Toc/index.astro'
1515
1616
/** Components made available for use in MDX */
1717
import Avatar from '@components/Avatar/index.astro'
18+
import Button from '@components/Button/index.astro'
19+
import Calendar from '@components/Calendar/index.astro'
1820
import Callout from '@components/Callout/index.astro'
1921
import Carousel from '@components/Carousel/index.astro'
2022
import Contact from '@components/CallToAction/Contact/index.astro'
@@ -34,6 +36,8 @@ import CodeTabs from '@components/Code/CodeTabs/index.astro'
3436
/** Export components for use in MDX */
3537
const Components = {
3638
Avatar,
39+
Button,
40+
Calendar,
3741
Callout,
3842
Carousel,
3943
Contact,

0 commit comments

Comments
 (0)