Skip to content

Commit dc98ff2

Browse files
committed
Update Webmentions and Toast NetworkStatus components to use Icon component
1 parent b1c0edc commit dc98ff2

12 files changed

Lines changed: 168 additions & 62 deletions

File tree

src/components/Callout/index.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ const typeLabelMap = {
2121
const iconMap = {
2222
warning: 'warning',
2323
action: 'warning',
24-
info: 'info-circled',
24+
info: 'info',
2525
tip: 'lightbulb',
26-
note: 'info-circled',
26+
note: 'info',
2727
success: 'check',
2828
danger: 'warning',
2929
} as const

src/components/Icon/icons/info-circled.astro renamed to src/components/Icon/icons/a.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ const { color, classes, size, accessible, focusable, isListMarker, id } = Astro.
2222
aria-hidden={accessible ? "false" : "true"}
2323
focusable={focusable ? "true" : "false"}
2424
>
25-
{accessible && <title>info circled icon</title>}
25+
{accessible && <title>Example Icon</title>}
2626
<path
2727
stroke-linecap="round"
2828
stroke-linejoin="round"
2929
stroke-width="2"
30-
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
30+
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
3131
></path>
3232
</svg>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
export type Props = {
3+
color: string
4+
classes?: string
5+
size: number
6+
accessible: boolean
7+
focusable: boolean
8+
isListMarker?: boolean
9+
id?: string
10+
}
11+
12+
const { color, classes, size, accessible, focusable, isListMarker, id } = Astro.props
13+
---
14+
15+
<svg
16+
id={id}
17+
xmlns="http://www.w3.org/2000/svg"
18+
class:list={["shrink-0", `w-${size} h-${size}`, `text-${color}`, classes, isListMarker ? "mt-0.5" : ""]}
19+
fill="currentColor"
20+
stroke="none"
21+
viewBox="0 0 24 24"
22+
aria-hidden={accessible ? "false" : "true"}
23+
focusable={focusable ? "true" : "false"}
24+
>
25+
{accessible && <title>Example Icon</title>}
26+
<path
27+
stroke-linecap="round"
28+
stroke-linejoin="round"
29+
stroke-width="2"
30+
d="M4.5 12c0-1.232.046-2.453.138-3.662a4.006 4.006 0 013.7-3.7 48.678 48.678 0 017.324 0 4.006 4.006 0 013.7 3.7c.017.22.032.441.046.662M4.5 12l-3-3m3 3l3-3m12 3c0 1.232-.046 2.453-.138 3.662a4.006 4.006 0 01-3.7 3.7 48.657 48.657 0 01-7.324 0 4.006 4.006 0 01-3.7-3.7c-.017-.22-.032-.441-.046-.662M19.5 12l-3 3m3-3l3 3"
31+
></path>
32+
</svg>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
export type Props = {
3+
color: string
4+
classes?: string
5+
size: number
6+
accessible: boolean
7+
focusable: boolean
8+
isListMarker?: boolean
9+
id?: string
10+
}
11+
12+
const { color, classes, size, accessible, focusable, isListMarker, id } = Astro.props
13+
---
14+
15+
<svg
16+
id={id}
17+
xmlns="http://www.w3.org/2000/svg"
18+
class:list={["shrink-0", `w-${size} h-${size}`, `text-${color}`, classes, isListMarker ? "mt-0.5" : ""]}
19+
fill="none"
20+
stroke="currentColor"
21+
viewBox="0 0 24 24"
22+
aria-hidden={accessible ? "false" : "true"}
23+
focusable={focusable ? "true" : "false"}
24+
>
25+
{accessible && <title>Check Circled Open Icon</title>}
26+
<path
27+
stroke-linecap="round"
28+
stroke-linejoin="round"
29+
stroke-width="2"
30+
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
31+
></path>
32+
</svg>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
export type Props = {
3+
color: string
4+
classes?: string
5+
size: number
6+
accessible: boolean
7+
focusable: boolean
8+
isListMarker?: boolean
9+
id?: string
10+
}
11+
12+
const { color, classes, size, accessible, focusable, isListMarker, id } = Astro.props
13+
---
14+
15+
<svg
16+
id={id}
17+
xmlns="http://www.w3.org/2000/svg"
18+
class:list={["shrink-0", `w-${size} h-${size}`, `text-${color}`, classes, isListMarker ? "mt-0.5" : ""]}
19+
fill="currentColor"
20+
stroke="none"
21+
viewBox="0 0 24 24"
22+
aria-hidden={accessible ? "false" : "true"}
23+
focusable={focusable ? "true" : "false"}
24+
>
25+
{accessible && <title>Heart Filled Icon</title>}
26+
<path
27+
stroke-linecap="round"
28+
stroke-linejoin="round"
29+
stroke-width="2"
30+
d="M11.645 20.91l-.007-.003-.022-.012a15.247 15.247 0 01-.383-.218 25.18 25.18 0 01-4.244-3.17C4.688 15.36 2.25 12.174 2.25 8.25 2.25 5.322 4.714 3 7.688 3A5.5 5.5 0 0112 5.052 5.5 5.5 0 0116.313 3c2.973 0 5.437 2.322 5.437 5.25 0 3.925-2.438 7.111-4.739 9.256a25.175 25.175 0 01-4.244 3.17 15.247 15.247 0 01-.383.219l-.022.012-.007.004-.003.001a.752.752 0 01-.704 0l-.003-.001z"
31+
></path>
32+
</svg>

src/components/Icon/icons/info.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ const { color, classes, size, accessible, focusable, isListMarker, id } = Astro.
2222
aria-hidden={accessible ? "false" : "true"}
2323
focusable={focusable ? "true" : "false"}
2424
>
25-
{accessible && <title>info icon</title>}
25+
{accessible && <title>info circled icon</title>}
2626
<path
2727
stroke-linecap="round"
2828
stroke-linejoin="round"
2929
stroke-width="2"
30-
d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"
30+
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
3131
></path>
3232
</svg>

src/components/List/layouts/ZebraList.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const textClass = ["text-sm text-content-offset"]
3131
<span class:list={textClass}>{item.text}</span>
3232
</div>
3333
<Icon
34-
icon={"info-circled"}
34+
icon={"info"}
3535
color={"text-trim"}
3636
size={4}
3737
classes={`group-hover:${item.color ?? "text-primary"} transition-colors`}

src/components/Toasts/NetworkStatus/client/index.ts

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { LitElement, html } from 'lit'
2+
import { unsafeHTML } from 'lit/directives/unsafe-html.js'
23
import { defineCustomElement } from '@components/scripts/utils'
34
import type { WebComponentModule } from '@components/scripts/@types/webComponentModule'
4-
import { queryConnectionStatusIndicator } from './selectors'
5+
import { queryConnectionStatusIndicator, queryNetworkStatusIconMarkup } from './selectors'
56

67
type ToastType = 'success' | 'error'
78

89
const TOAST_HIDE_TIMEOUT = 3000
10+
const ICON_BANK_ID = 'network-status-toast-icon-bank'
911

1012
export class NetworkStatusToastElement extends LitElement {
1113
static registeredName = 'network-status-toast'
@@ -118,6 +120,22 @@ export class NetworkStatusToastElement extends LitElement {
118120
}
119121

120122
protected override render() {
123+
const canUseDocument = typeof document !== 'undefined'
124+
const successIconMarkup = canUseDocument
125+
? queryNetworkStatusIconMarkup({
126+
iconBankId: ICON_BANK_ID,
127+
iconName: 'success',
128+
root: document,
129+
})
130+
: null
131+
const errorIconMarkup = canUseDocument
132+
? queryNetworkStatusIconMarkup({
133+
iconBankId: ICON_BANK_ID,
134+
iconName: 'error',
135+
root: document,
136+
})
137+
: null
138+
121139
return html`
122140
<div
123141
data-network-status-toast
@@ -128,36 +146,8 @@ export class NetworkStatusToastElement extends LitElement {
128146
aria-atomic="true"
129147
>
130148
<div class="flex items-center space-x-2">
131-
<svg
132-
class="w-5 h-5 success-icon"
133-
fill="none"
134-
stroke="currentColor"
135-
viewBox="0 0 24 24"
136-
aria-hidden="true"
137-
focusable="false"
138-
>
139-
<path
140-
stroke-linecap="round"
141-
stroke-linejoin="round"
142-
stroke-width="2"
143-
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
144-
></path>
145-
</svg>
146-
<svg
147-
class="w-5 h-5 error-icon hidden"
148-
fill="none"
149-
stroke="currentColor"
150-
viewBox="0 0 24 24"
151-
aria-hidden="true"
152-
focusable="false"
153-
>
154-
<path
155-
stroke-linecap="round"
156-
stroke-linejoin="round"
157-
stroke-width="2"
158-
d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
159-
></path>
160-
</svg>
149+
<span class="success-icon">${successIconMarkup ? unsafeHTML(successIconMarkup) : null}</span>
150+
<span class="error-icon hidden">${errorIconMarkup ? unsafeHTML(errorIconMarkup) : null}</span>
161151
<span class="toast-message">${this.message}</span>
162152
</div>
163153
</div>

src/components/Toasts/NetworkStatus/client/selectors.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,28 @@ export function queryConnectionStatusIndicator(root: ParentNode = document): HTM
5555

5656
return candidate
5757
}
58+
59+
export function queryNetworkStatusIconMarkup(params: {
60+
iconBankId: string
61+
iconName: 'success' | 'error'
62+
root?: Document
63+
}): string | null {
64+
const { iconBankId, iconName, root = document } = params
65+
66+
if (!iconBankId || !iconName) {
67+
return null
68+
}
69+
70+
const iconBankCandidate = root.getElementById(iconBankId)
71+
if (!isDivElement(iconBankCandidate)) {
72+
return null
73+
}
74+
75+
const iconHostCandidate = iconBankCandidate.querySelector(`[data-network-status-icon="${iconName}"]`)
76+
if (!isSpanElement(iconHostCandidate)) {
77+
return null
78+
}
79+
80+
const markup = iconHostCandidate.innerHTML.trim()
81+
return markup ? markup : null
82+
}

src/components/Toasts/NetworkStatus/index.astro

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,21 @@
1111
* <NetworkStatus />
1212
* ```
1313
*/
14+
import Icon from '@components/Icon/index.astro'
1415
import styles from './index.module.css'
16+
17+
const iconBankId = 'network-status-toast-icon-bank'
1518
---
1619

20+
<div id={iconBankId} hidden aria-hidden="true">
21+
<span data-network-status-icon="success">
22+
<Icon icon="check-circled-open" color="inherit" size={5} isListMarker={false} />
23+
</span>
24+
<span data-network-status-icon="error">
25+
<Icon icon="info" color="inherit" size={5} isListMarker={false} />
26+
</span>
27+
</div>
28+
1729
<network-status-toast
1830
class:list={['network-status-toast', styles.toastHost]}
1931
data-testid="network-status-toast"></network-status-toast>

0 commit comments

Comments
 (0)