webcoreui 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +30 -1
  2. package/astro.d.ts +15 -0
  3. package/astro.js +10 -0
  4. package/components/Accordion/Accordion.astro +32 -20
  5. package/components/Accordion/Accordion.svelte +22 -4
  6. package/components/Accordion/Accordion.tsx +29 -7
  7. package/components/Accordion/accordion.module.scss +12 -0
  8. package/components/Accordion/accordion.ts +4 -0
  9. package/components/AspectRatio/AspectRatio.astro +21 -0
  10. package/components/AspectRatio/AspectRatio.svelte +19 -0
  11. package/components/AspectRatio/AspectRatio.tsx +28 -0
  12. package/components/AspectRatio/aspect-ratio.module.scss +10 -0
  13. package/components/AspectRatio/aspectratio.ts +8 -0
  14. package/components/Banner/Banner.astro +56 -0
  15. package/components/Banner/Banner.svelte +47 -0
  16. package/components/Banner/Banner.tsx +54 -0
  17. package/components/Banner/banner.module.scss +57 -0
  18. package/components/Banner/banner.ts +12 -0
  19. package/components/Button/button.ts +1 -1
  20. package/components/Carousel/Carousel.astro +16 -7
  21. package/components/Carousel/Carousel.svelte +15 -5
  22. package/components/Carousel/Carousel.tsx +15 -5
  23. package/components/Carousel/carousel.module.scss +4 -1
  24. package/components/Carousel/carousel.ts +1 -1
  25. package/components/DataTable/DataTable.astro +2 -2
  26. package/components/DataTable/DataTable.tsx +287 -287
  27. package/components/Icon/map.ts +2 -0
  28. package/components/Kbd/Kbd.astro +20 -0
  29. package/components/Kbd/Kbd.svelte +18 -0
  30. package/components/Kbd/Kbd.tsx +27 -0
  31. package/components/Kbd/kbd.module.scss +8 -0
  32. package/components/Kbd/kbd.ts +26 -0
  33. package/components/Kbd/keyMap.ts +21 -0
  34. package/components/Pagination/Pagination.astro +2 -0
  35. package/components/Pagination/Pagination.svelte +6 -3
  36. package/components/Pagination/Pagination.tsx +5 -3
  37. package/components/Pagination/pagination.ts +1 -0
  38. package/components/Spoiler/Spoiler.astro +50 -0
  39. package/components/Spoiler/Spoiler.svelte +45 -0
  40. package/components/Spoiler/Spoiler.tsx +50 -0
  41. package/components/Spoiler/spoiler.module.scss +40 -0
  42. package/components/Spoiler/spoiler.ts +11 -0
  43. package/components/Stepper/Stepper.astro +61 -0
  44. package/components/Stepper/Stepper.svelte +59 -0
  45. package/components/Stepper/Stepper.tsx +60 -0
  46. package/components/Stepper/stepper.module.scss +102 -0
  47. package/components/Stepper/stepper.ts +17 -0
  48. package/icons/close.svg +1 -1
  49. package/icons/plus.svg +3 -0
  50. package/icons.d.ts +1 -0
  51. package/icons.js +1 -0
  52. package/index.d.ts +8 -0
  53. package/index.js +1 -0
  54. package/package.json +5 -4
  55. package/react.d.ts +15 -0
  56. package/react.js +10 -0
  57. package/scss/config/typography.scss +3 -1
  58. package/scss/global/utility.scss +5 -1
  59. package/scss/resets.scss +5 -0
  60. package/svelte.d.ts +15 -0
  61. package/svelte.js +10 -0
  62. package/utils/DOMUtils.ts +28 -0
  63. package/scss/global/elements.scss +0 -31
@@ -1,287 +1,287 @@
1
- import React, { useState } from 'react'
2
- import type { HeadingObject, ReactDataTableProps } from './datatable'
3
-
4
- import Button from '../Button/Button.tsx'
5
- import ConditionalWrapper from '../ConditionalWrapper/ConditionalWrapper.tsx'
6
- import Input from '../Input/Input.tsx'
7
- import Pagination from '../Pagination/Pagination.tsx'
8
- import Select from '../Select/Select.tsx'
9
-
10
- import { classNames } from '../../utils/classNames'
11
- import { debounce } from '../../utils/debounce'
12
-
13
- import checkIcon from '../../icons/check.svg?raw'
14
- import orderIcon from '../../icons/order.svg?raw'
15
- import searchIcon from '../../icons/search.svg?raw'
16
-
17
- import styles from './datatable.module.scss'
18
-
19
- import type { ListEventType } from '../List/list'
20
-
21
- // eslint-disable-next-line complexity
22
- const DataTable = ({
23
- headings,
24
- filterPlaceholder = 'Filter entries',
25
- showFilterIcon,
26
- noResultsLabel = 'No results.',
27
- itemsPerPage,
28
- subText,
29
- columnToggleLabel = 'Columns',
30
- pagination,
31
- data,
32
- hover,
33
- striped,
34
- offsetStripe,
35
- compact,
36
- maxHeight,
37
- className,
38
- id,
39
- onFilter,
40
- children
41
- }: ReactDataTableProps) => {
42
- const [filteredData, setFilteredData] = useState<any>(data)
43
- const [toggledData, setToggledData] = useState(filteredData)
44
- const [filteredHeadings, setFilteredHeadings] = useState<any>(headings)
45
- const [page, setPage] = useState(1)
46
- const [hasActiveFilter, setHasActiveFilter] = useState(false)
47
- const [sortOrder, setSortOrder] = useState(1)
48
-
49
- const classes = classNames([
50
- styles.table,
51
- hover && styles.hover,
52
- striped && styles[`striped-${striped}s`],
53
- offsetStripe && styles.offset,
54
- compact && styles.compact,
55
- maxHeight && styles.scroll
56
- ])
57
-
58
- const footerClasses = classNames([
59
- styles.footer,
60
- subText && styles.between
61
- ])
62
-
63
- const styleVariables = {
64
- ...(maxHeight && { 'max-height': maxHeight })
65
- } as React.CSSProperties
66
-
67
- const showColumnToggle = headings?.some(heading => {
68
- return typeof heading === 'string' ? false : heading.toggleable
69
- })
70
-
71
- const columnToggleItems = [{
72
- items: headings?.length ? headings
73
- .filter(heading => typeof heading !== 'string' && heading.toggleable)
74
- .map(heading => ({
75
- icon: checkIcon,
76
- name: (heading as HeadingObject).name,
77
- value: String(headings.findIndex(h => {
78
- return (h as HeadingObject).name === (heading as HeadingObject).name
79
- }))
80
- })) : []
81
- }]
82
-
83
- const columnFilterIndexes = headings?.map(heading => (heading as HeadingObject).filterable)
84
- .map((heading, index) => heading ? index : null)
85
- .filter(heading => heading !== null) || []
86
-
87
- const hasPagination = data?.length && itemsPerPage
88
- ? data.length > itemsPerPage
89
- : false
90
-
91
- const filter = debounce((event: Event) => {
92
- const target = event.target as HTMLInputElement
93
-
94
- setHasActiveFilter(!!target.value)
95
-
96
- setFilteredData(toggledData?.filter((row: string[]) => {
97
- const rowValue = row.filter((_, index) => columnFilterIndexes.includes(index))
98
- .join('')
99
- .toLowerCase()
100
-
101
- return rowValue.includes(target.value.toLowerCase())
102
- }))
103
-
104
- onFilter?.({
105
- results: filteredData,
106
- numberOfResults: filteredData.length
107
- })
108
- }, 400)
109
-
110
- const toggleColumns = (event: ListEventType) => {
111
- const columnToggleListElement = Array.from(event.list.children)
112
- .find(child => (child as HTMLLIElement).dataset.name === event.name) as HTMLLIElement
113
- const svgIcon = columnToggleListElement.children[0] as HTMLElement
114
- let mappedData
115
-
116
- svgIcon.style.opacity = svgIcon.style.opacity === '0'
117
- ? '1'
118
- : '0'
119
-
120
- if (svgIcon.style.opacity === '0') {
121
- mappedData = (hasActiveFilter ? data : filteredData)?.map((row: string[]) => {
122
- return row.map((column, index) => index === Number(event.value) ? null : column)
123
- })
124
-
125
- setFilteredData(mappedData)
126
-
127
- setFilteredHeadings(filteredHeadings.map((heading: HeadingObject | string) => {
128
- return ((heading as HeadingObject)?.name || heading) === event.name ? null : heading
129
- }))
130
- } else {
131
- mappedData = (hasActiveFilter ? data : filteredData)?.map((row: string[], x: number) => {
132
- return row.map((column, y) => y === Number(event.value) ? data?.[x][y] : column)
133
- })
134
-
135
- setFilteredData(mappedData)
136
-
137
- setFilteredHeadings(filteredHeadings.map((heading: HeadingObject | string, index: number) => {
138
- return ((headings?.[index] as HeadingObject)?.name || headings?.[index]) === event.name
139
- ? headings?.[index]
140
- : heading
141
- }))
142
- }
143
-
144
- setToggledData(mappedData)
145
- }
146
-
147
- const sort = (index: number) => {
148
- const sortedData = filteredData.sort((a: string[], b: string[]) => {
149
- let aValue: string | number = a[index]
150
- let bValue: string | number = b[index]
151
-
152
- if (!isNaN(aValue as any)) {
153
- aValue = Number(aValue)
154
- }
155
-
156
- if (!isNaN(bValue as any)) {
157
- bValue = Number(bValue)
158
- }
159
-
160
- return aValue > bValue
161
- ? sortOrder * -1
162
- : sortOrder
163
- })
164
-
165
- setFilteredData(sortedData)
166
- setSortOrder(sortOrder === 1 ? -1 : 1)
167
- }
168
-
169
- const isNextPage = (index: number) => {
170
- if (hasPagination && itemsPerPage && !hasActiveFilter) {
171
- const currentPage = Math.ceil((index + 1) / itemsPerPage)
172
-
173
- return currentPage !== page ? 'true' : undefined
174
- }
175
-
176
- if (hasActiveFilter && itemsPerPage) {
177
- return index >= itemsPerPage ? 'true' : undefined
178
- }
179
-
180
- return undefined
181
- }
182
-
183
- return (
184
- <section className={className} id={id}>
185
- {(!!columnFilterIndexes?.length || showColumnToggle) && (
186
- <div className={styles.filters}>
187
- {!!columnFilterIndexes?.length && (
188
- <Input
189
- type="search"
190
- placeholder={filterPlaceholder}
191
- onInput={filter}
192
- >
193
- {showFilterIcon && (
194
- <span dangerouslySetInnerHTML={{ __html: searchIcon }} />
195
- )}
196
- </Input>
197
- )}
198
- {showColumnToggle && (
199
- <Select
200
- name={`data-table-${id || crypto.randomUUID()}`}
201
- itemGroups={columnToggleItems}
202
- position="bottom-end"
203
- value={columnToggleLabel}
204
- onChange={toggleColumns}
205
- updateValue={false}
206
- />
207
- )}
208
- </div>
209
- )}
210
-
211
- <div className={classes} style={styleVariables}>
212
- <table>
213
- {!!filteredHeadings?.length && (
214
- <thead>
215
- <tr>
216
- {filteredHeadings?.map((heading: HeadingObject | string, index: number) => {
217
- if (!heading) {
218
- return null
219
- }
220
-
221
- return (
222
- <th key={index}>
223
- <ConditionalWrapper
224
- condition={!!(heading as HeadingObject).sortable}
225
- wrapper={children => (
226
- <Button theme="flat" slot="wrapper" onClick={() => sort(index)}>
227
- {children}
228
- <span dangerouslySetInnerHTML={{ __html: orderIcon }} />
229
- </Button>
230
- )}
231
- >
232
- {(heading as HeadingObject).name || heading as string}
233
- </ConditionalWrapper>
234
- </th>
235
- )
236
- })}
237
- </tr>
238
- </thead>
239
- )}
240
-
241
- <tbody>
242
- {filteredData?.map((row: string[], rowIndex: number) => (
243
- <tr key={rowIndex} data-hidden={isNextPage(rowIndex)}>
244
- {row.filter(Boolean).map((column, columnIndex) => (
245
- <td
246
- key={columnIndex}
247
- dangerouslySetInnerHTML={{ __html: column }}
248
- />
249
- ))}
250
- </tr>
251
- ))}
252
- {children}
253
- </tbody>
254
- {!filteredData?.length && (
255
- <tfoot>
256
- <tr>
257
- <td
258
- colSpan={data?.[0].length}
259
- className={styles['no-results']}
260
- >
261
- {noResultsLabel}
262
- </td>
263
- </tr>
264
- </tfoot>
265
- )}
266
- </table>
267
- </div>
268
- {(subText || hasPagination) && (
269
- <div className={footerClasses}>
270
- {subText && (
271
- <span className={styles.subtext}>{subText}</span>
272
- )}
273
- {(hasPagination && itemsPerPage && !hasActiveFilter) && (
274
- <Pagination
275
- {...pagination}
276
- totalPages={Math.ceil((data?.length || 0) / itemsPerPage)}
277
- currentPage={page}
278
- onChange={event => setPage(event.page)}
279
- />
280
- )}
281
- </div>
282
- )}
283
- </section>
284
- )
285
- }
286
-
287
- export default DataTable
1
+ import React, { useState } from 'react'
2
+ import type { HeadingObject, ReactDataTableProps } from './datatable'
3
+
4
+ import Button from '../Button/Button.tsx'
5
+ import ConditionalWrapper from '../ConditionalWrapper/ConditionalWrapper.tsx'
6
+ import Input from '../Input/Input.tsx'
7
+ import Pagination from '../Pagination/Pagination.tsx'
8
+ import Select from '../Select/Select.tsx'
9
+
10
+ import { classNames } from '../../utils/classNames'
11
+ import { debounce } from '../../utils/debounce'
12
+
13
+ import checkIcon from '../../icons/check.svg?raw'
14
+ import orderIcon from '../../icons/order.svg?raw'
15
+ import searchIcon from '../../icons/search.svg?raw'
16
+
17
+ import styles from './datatable.module.scss'
18
+
19
+ import type { ListEventType } from '../List/list'
20
+
21
+ // eslint-disable-next-line complexity
22
+ const DataTable = ({
23
+ headings,
24
+ filterPlaceholder = 'Filter entries',
25
+ showFilterIcon,
26
+ noResultsLabel = 'No results.',
27
+ itemsPerPage,
28
+ subText,
29
+ columnToggleLabel = 'Columns',
30
+ pagination,
31
+ data,
32
+ hover,
33
+ striped,
34
+ offsetStripe,
35
+ compact,
36
+ maxHeight,
37
+ className,
38
+ id,
39
+ onFilter,
40
+ children
41
+ }: ReactDataTableProps) => {
42
+ const [filteredData, setFilteredData] = useState<any>(data)
43
+ const [toggledData, setToggledData] = useState(filteredData)
44
+ const [filteredHeadings, setFilteredHeadings] = useState<any>(headings)
45
+ const [page, setPage] = useState(1)
46
+ const [hasActiveFilter, setHasActiveFilter] = useState(false)
47
+ const [sortOrder, setSortOrder] = useState(1)
48
+
49
+ const classes = classNames([
50
+ styles.table,
51
+ hover && styles.hover,
52
+ striped && styles[`striped-${striped}s`],
53
+ offsetStripe && styles.offset,
54
+ compact && styles.compact,
55
+ maxHeight && styles.scroll
56
+ ])
57
+
58
+ const footerClasses = classNames([
59
+ styles.footer,
60
+ subText && styles.between
61
+ ])
62
+
63
+ const styleVariables = {
64
+ ...(maxHeight && { maxHeight })
65
+ } as React.CSSProperties
66
+
67
+ const showColumnToggle = headings?.some(heading => {
68
+ return typeof heading === 'string' ? false : heading.toggleable
69
+ })
70
+
71
+ const columnToggleItems = [{
72
+ items: headings?.length ? headings
73
+ .filter(heading => typeof heading !== 'string' && heading.toggleable)
74
+ .map(heading => ({
75
+ icon: checkIcon,
76
+ name: (heading as HeadingObject).name,
77
+ value: String(headings.findIndex(h => {
78
+ return (h as HeadingObject).name === (heading as HeadingObject).name
79
+ }))
80
+ })) : []
81
+ }]
82
+
83
+ const columnFilterIndexes = headings?.map(heading => (heading as HeadingObject).filterable)
84
+ .map((heading, index) => heading ? index : null)
85
+ .filter(heading => heading !== null) || []
86
+
87
+ const hasPagination = data?.length && itemsPerPage
88
+ ? data.length > itemsPerPage
89
+ : false
90
+
91
+ const filter = debounce((event: Event) => {
92
+ const target = event.target as HTMLInputElement
93
+
94
+ setHasActiveFilter(!!target.value)
95
+
96
+ setFilteredData(toggledData?.filter((row: string[]) => {
97
+ const rowValue = row.filter((_, index) => columnFilterIndexes.includes(index))
98
+ .join('')
99
+ .toLowerCase()
100
+
101
+ return rowValue.includes(target.value.toLowerCase())
102
+ }))
103
+
104
+ onFilter?.({
105
+ results: filteredData,
106
+ numberOfResults: filteredData.length
107
+ })
108
+ }, 400)
109
+
110
+ const toggleColumns = (event: ListEventType) => {
111
+ const columnToggleListElement = Array.from(event.list.children)
112
+ .find(child => (child as HTMLLIElement).dataset.name === event.name) as HTMLLIElement
113
+ const svgIcon = columnToggleListElement.children[0] as HTMLElement
114
+ let mappedData
115
+
116
+ svgIcon.style.opacity = svgIcon.style.opacity === '0'
117
+ ? '1'
118
+ : '0'
119
+
120
+ if (svgIcon.style.opacity === '0') {
121
+ mappedData = (hasActiveFilter ? data : filteredData)?.map((row: string[]) => {
122
+ return row.map((column, index) => index === Number(event.value) ? null : column)
123
+ })
124
+
125
+ setFilteredData(mappedData)
126
+
127
+ setFilteredHeadings(filteredHeadings.map((heading: HeadingObject | string) => {
128
+ return ((heading as HeadingObject)?.name || heading) === event.name ? null : heading
129
+ }))
130
+ } else {
131
+ mappedData = (hasActiveFilter ? data : filteredData)?.map((row: string[], x: number) => {
132
+ return row.map((column, y) => y === Number(event.value) ? data?.[x][y] : column)
133
+ })
134
+
135
+ setFilteredData(mappedData)
136
+
137
+ setFilteredHeadings(filteredHeadings.map((heading: HeadingObject | string, index: number) => {
138
+ return ((headings?.[index] as HeadingObject)?.name || headings?.[index]) === event.name
139
+ ? headings?.[index]
140
+ : heading
141
+ }))
142
+ }
143
+
144
+ setToggledData(mappedData)
145
+ }
146
+
147
+ const sort = (index: number) => {
148
+ const sortedData = filteredData.sort((a: string[], b: string[]) => {
149
+ let aValue: string | number = a[index]
150
+ let bValue: string | number = b[index]
151
+
152
+ if (!isNaN(aValue as any)) {
153
+ aValue = Number(aValue)
154
+ }
155
+
156
+ if (!isNaN(bValue as any)) {
157
+ bValue = Number(bValue)
158
+ }
159
+
160
+ return aValue > bValue
161
+ ? sortOrder * -1
162
+ : sortOrder
163
+ })
164
+
165
+ setFilteredData(sortedData)
166
+ setSortOrder(sortOrder === 1 ? -1 : 1)
167
+ }
168
+
169
+ const isNextPage = (index: number) => {
170
+ if (hasPagination && itemsPerPage && !hasActiveFilter) {
171
+ const currentPage = Math.ceil((index + 1) / itemsPerPage)
172
+
173
+ return currentPage !== page ? 'true' : undefined
174
+ }
175
+
176
+ if (hasActiveFilter && itemsPerPage) {
177
+ return index >= itemsPerPage ? 'true' : undefined
178
+ }
179
+
180
+ return undefined
181
+ }
182
+
183
+ return (
184
+ <section className={className} id={id}>
185
+ {(!!columnFilterIndexes?.length || showColumnToggle) && (
186
+ <div className={styles.filters}>
187
+ {!!columnFilterIndexes?.length && (
188
+ <Input
189
+ type="search"
190
+ placeholder={filterPlaceholder}
191
+ onInput={filter}
192
+ >
193
+ {showFilterIcon && (
194
+ <span dangerouslySetInnerHTML={{ __html: searchIcon }} />
195
+ )}
196
+ </Input>
197
+ )}
198
+ {showColumnToggle && (
199
+ <Select
200
+ name={`data-table-${id || crypto.randomUUID()}`}
201
+ itemGroups={columnToggleItems}
202
+ position="bottom-end"
203
+ value={columnToggleLabel}
204
+ onChange={toggleColumns}
205
+ updateValue={false}
206
+ />
207
+ )}
208
+ </div>
209
+ )}
210
+
211
+ <div className={classes} style={styleVariables}>
212
+ <table>
213
+ {!!filteredHeadings?.length && (
214
+ <thead>
215
+ <tr>
216
+ {filteredHeadings?.map((heading: HeadingObject | string, index: number) => {
217
+ if (!heading) {
218
+ return null
219
+ }
220
+
221
+ return (
222
+ <th key={index}>
223
+ <ConditionalWrapper
224
+ condition={!!(heading as HeadingObject).sortable}
225
+ wrapper={children => (
226
+ <Button theme="flat" slot="wrapper" onClick={() => sort(index)}>
227
+ {children}
228
+ <span dangerouslySetInnerHTML={{ __html: orderIcon }} />
229
+ </Button>
230
+ )}
231
+ >
232
+ {(heading as HeadingObject).name || heading as string}
233
+ </ConditionalWrapper>
234
+ </th>
235
+ )
236
+ })}
237
+ </tr>
238
+ </thead>
239
+ )}
240
+
241
+ <tbody>
242
+ {filteredData?.map((row: string[], rowIndex: number) => (
243
+ <tr key={rowIndex} data-hidden={isNextPage(rowIndex)}>
244
+ {row.filter(Boolean).map((column, columnIndex) => (
245
+ <td
246
+ key={columnIndex}
247
+ dangerouslySetInnerHTML={{ __html: column }}
248
+ />
249
+ ))}
250
+ </tr>
251
+ ))}
252
+ {children}
253
+ </tbody>
254
+ {!filteredData?.length && (
255
+ <tfoot>
256
+ <tr>
257
+ <td
258
+ colSpan={data?.[0].length}
259
+ className={styles['no-results']}
260
+ >
261
+ {noResultsLabel}
262
+ </td>
263
+ </tr>
264
+ </tfoot>
265
+ )}
266
+ </table>
267
+ </div>
268
+ {(subText || hasPagination) && (
269
+ <div className={footerClasses}>
270
+ {subText && (
271
+ <span className={styles.subtext}>{subText}</span>
272
+ )}
273
+ {(hasPagination && itemsPerPage && !hasActiveFilter) && (
274
+ <Pagination
275
+ {...pagination}
276
+ totalPages={Math.ceil((data?.length || 0) / itemsPerPage)}
277
+ currentPage={page}
278
+ onChange={event => setPage(event.page)}
279
+ />
280
+ )}
281
+ </div>
282
+ )}
283
+ </section>
284
+ )
285
+ }
286
+
287
+ export default DataTable
@@ -13,6 +13,7 @@ import Home from '../../icons/home.svg?raw'
13
13
  import Info from '../../icons/info.svg?raw'
14
14
  import Moon from '../../icons/moon.svg?raw'
15
15
  import Order from '../../icons/order.svg?raw'
16
+ import Plus from '../../icons/plus.svg?raw'
16
17
  import Search from '../../icons/search.svg?raw'
17
18
  import Sun from '../../icons/sun.svg?raw'
18
19
  import Warning from '../../icons/warning.svg?raw'
@@ -33,6 +34,7 @@ const iconMap = {
33
34
  'info': Info,
34
35
  'moon': Moon,
35
36
  'order': Order,
37
+ 'plus': Plus,
36
38
  'search': Search,
37
39
  'sun': Sun,
38
40
  'warning': Warning
@@ -0,0 +1,20 @@
1
+ ---
2
+ import type { KbdProps } from './kbd'
3
+ import { keyMap } from './keyMap'
4
+
5
+ import styles from './kbd.module.scss'
6
+
7
+ interface Props extends KbdProps {}
8
+
9
+ const {
10
+ keys,
11
+ className
12
+ } = Astro.props
13
+
14
+ const classes = [
15
+ styles.kbd,
16
+ className
17
+ ]
18
+ ---
19
+
20
+ <kbd class:list={classes}>{keys?.map(key => keyMap[key])}<slot /></kbd>
@@ -0,0 +1,18 @@
1
+ <script lang="ts">
2
+ import type { KbdProps } from './kbd'
3
+ import { keyMap } from './keyMap'
4
+
5
+ import { classNames } from '../../utils/classNames'
6
+
7
+ import styles from './kbd.module.scss'
8
+
9
+ export let keys: KbdProps['keys'] = []
10
+ export let className: KbdProps['className'] = ''
11
+
12
+ const classes = classNames([
13
+ styles.kbd,
14
+ className
15
+ ])
16
+ </script>
17
+
18
+ <kbd class={classes}>{keys?.map(key => keyMap[key]).join('')}<slot /></kbd>
@@ -0,0 +1,27 @@
1
+ import React from 'react'
2
+ import type { ReactKbdProps } from './kbd'
3
+ import { keyMap } from './keyMap'
4
+
5
+ import { classNames } from '../../utils/classNames'
6
+
7
+ import styles from './kbd.module.scss'
8
+
9
+ const Kbd = ({
10
+ keys,
11
+ className,
12
+ children
13
+ }: ReactKbdProps) => {
14
+ const classes = classNames([
15
+ styles.kbd,
16
+ className
17
+ ])
18
+
19
+ return (
20
+ <kbd className={classes}>
21
+ {keys?.map(key => keyMap[key]).join('')}
22
+ {children}
23
+ </kbd>
24
+ )
25
+ }
26
+
27
+ export default Kbd