Skip to content

Commit d3ebdb2

Browse files
committed
✨ Add Svelte and React playgrounds for interactive component
1 parent 8661cab commit d3ebdb2

17 files changed

+209
-39
lines changed

src/components/Card/card.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export type CardProps = {
55
compact?: boolean
66
className?: string
77
secondary?: boolean
8+
[key: string]: any
89
}

src/components/Checkbox/Checkbox.svelte

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
export let boxed: CheckboxProps['boxed'] = false
1414
export let color: CheckboxProps['color'] = ''
1515
export let onClick: () => any = () => {}
16-
16+
1717
const classes = [
1818
'w-checkbox',
1919
boxed && 'boxed',
@@ -25,13 +25,18 @@
2525
: null
2626
</script>
2727

28-
<label class={classes} style={style} on:click={onClick}>
28+
<label class={classes} style={style}>
2929
<ConditionalWrapper
3030
condition={!!(label && subText)}
3131
element="div"
3232
class="checkbox-wrapper"
3333
>
34-
<input type="checkbox" checked={checked} disabled={disabled} />
34+
<input
35+
type="checkbox"
36+
checked={checked}
37+
disabled={disabled}
38+
on:click={onClick}
39+
/>
3540
<span class="check">
3641
{@html check}
3742
</span>

src/components/Checkbox/Checkbox.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const Checkbox = ({
3030
: undefined
3131

3232
return (
33-
<label className={classes} style={style} onClick={onClick}>
33+
<label className={classes} style={style}>
3434
<ConditionalWrapper
3535
condition={!!(label && subText)}
3636
wrapper={children => (
@@ -43,6 +43,7 @@ const Checkbox = ({
4343
type="checkbox"
4444
checked={checked}
4545
disabled={disabled}
46+
onClick={onClick}
4647
/>
4748
<span
4849
className="check"

src/components/Radio/Radio.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ const style = color
3737
</div>
3838
<input
3939
type="radio"
40-
name={name}
40+
name={name}
41+
value={item.value}
4142
checked={item.selected}
4243
disabled={item.disabled}
4344
/>

src/components/Radio/Radio.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
>
3636
<input
3737
type="radio"
38-
name={name}
38+
name={name}
39+
value={item.value}
3940
checked={item.selected}
4041
disabled={item.disabled}
4142
on:change={onChange}

src/components/Radio/Radio.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ const Radio = ({
2929

3030
return (
3131
<div className={classes} style={style}>
32-
{items.map(item => (
32+
{items.map((item, index) => (
3333
<label className={[
3434
item.subText && 'col',
3535
item.disabled && 'disabled'
36-
].filter(Boolean).join(' ')}>
36+
].filter(Boolean).join(' ')} key={index}>
3737
<ConditionalWrapper
3838
condition={!!(item.subText)}
3939
wrapper={children => (
@@ -44,7 +44,8 @@ const Radio = ({
4444
>
4545
<input
4646
type="radio"
47-
name={name}
47+
name={name}
48+
value={item.value}
4849
checked={item.selected}
4950
disabled={item.disabled}
5051
onChange={onChange}

src/components/Radio/radio.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export type RadioProps = {
22
items: {
33
label: string
4+
value: string
45
subText?: string
56
selected?: boolean
67
disabled?: boolean

src/components/Switch/Switch.svelte

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@
2828
].filter(Boolean).join(' ')
2929
</script>
3030

31-
<label class={classes} style={styles || null} on:click={onClick}>
32-
<input type="checkbox" checked={toggled} disabled={disabled} />
31+
<label class={classes} style={styles || null}>
32+
<input
33+
type="checkbox"
34+
checked={toggled}
35+
disabled={disabled}
36+
on:click={onClick}
37+
/>
3338
<span class="toggle"></span>
3439
{#if label}
3540
<span class="label">{label}</span>

src/components/Switch/Switch.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ const Switch = ({
3333
} as React.CSSProperties
3434

3535
return (
36-
<label className={classes} style={styles || null} onClick={onClick}>
37-
<input type="checkbox" checked={toggled} disabled={disabled} />
36+
<label className={classes} style={styles || null}>
37+
<input
38+
type="checkbox"
39+
checked={toggled}
40+
disabled={disabled}
41+
onClick={onClick}
42+
/>
3843
<span className="toggle"></span>
3944
{label && <span className="label">{label}</span>}
4045
</label>

src/pages/accordion.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Layout from '@static/Layout.astro'
33
import ComponentWrapper from '@static/ComponentWrapper.astro'
44
55
import AstroAccordion from '@components/Accordion/Accordion.astro'
6-
import SvelteAccorion from '@components/Accordion/Accordion.svelte'
6+
import SvelteAccordion from '@components/Accordion/Accordion.svelte'
77
import ReactAccordion from '@components/Accordion/Accordion.tsx'
88
99
const accordionItems = [{
@@ -27,7 +27,7 @@ const accordionItems = [{
2727
</ComponentWrapper>
2828

2929
<ComponentWrapper type="Svelte">
30-
<SvelteAccorion items={accordionItems} client:load />
30+
<SvelteAccordion items={accordionItems} client:load />
3131
</ComponentWrapper>
3232

3333
<ComponentWrapper type="React">

src/pages/index.astro

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ import Checkbox from '@components/Checkbox/Checkbox.astro'
2828
<div class="cta">
2929
<Button
3030
href="https://github.com/Frontendland/webcoreui" target="_blank"
31-
theme="secondary"
3231
>
3332
<Icon type="github" size={20} />
3433
GitHub
3534
</Button>
35+
<Button theme="secondary" href="/svelte">
36+
Svelte Playground
37+
</Button>
38+
<Button theme="secondary" href="/react">
39+
React Playground
40+
</Button>
3641
</div>
3742
<div class="grid md-2 lg-3">
3843
<CardWrapper title="Accordion" href="/accordion">
@@ -106,7 +111,7 @@ import Checkbox from '@components/Checkbox/Checkbox.astro'
106111
</CardWrapper>
107112
<CardWrapper title="Radio" href="/radio">
108113
<Radio
109-
items={[{ label: 'Radio', selected: true }]}
114+
items={[{ label: 'Radio', selected: true, value: '1' }]}
110115
name="radio"
111116
/>
112117
</CardWrapper>
@@ -139,6 +144,9 @@ import Checkbox from '@components/Checkbox/Checkbox.astro'
139144

140145
.cta {
141146
text-align: center;
147+
display: flex;
148+
justify-content: center;
149+
gap: 10px;
142150
}
143151

144152
.grid {

src/pages/radio.astro

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ const sections = [
2727
<div class="grid md-2 lg-3">
2828
<ComponentWrapper type="Astro">
2929
<AstroRadio
30-
items={[{ label: 'Radio', selected: true }]}
30+
items={[{ label: 'Radio', selected: true, value: '1' }]}
3131
name="radio1"
3232
/>
3333
</ComponentWrapper>
3434

3535
<ComponentWrapper type="Svelte">
3636
<SvelteRadio
37-
items={[{ label: 'Radio', selected: true }]}
37+
items={[{ label: 'Radio', selected: true, value: '1' }]}
3838
name="radio2"
3939
color="#ee5253"
4040
/>
4141
</ComponentWrapper>
4242

4343
<ComponentWrapper type="React">
4444
<ReactRadio
45-
items={[{ label: 'Radio', selected: true }]}
45+
items={[{ label: 'Radio', selected: true, value: '1' }]}
4646
name="radio3"
4747
color="#48dbfb"
4848
/>
@@ -55,9 +55,9 @@ const sections = [
5555
<ComponentWrapper title="Default with link">
5656
<section.component
5757
items={[
58-
{ label: 'Small' },
59-
{ label: 'Medium with <a href="/" target="_blank">link</a>' },
60-
{ label: 'Large' }
58+
{ label: 'Small', value: 'sm' },
59+
{ label: 'Medium with <a href="/" target="_blank">link</a>', value: 'md' },
60+
{ label: 'Large', value: 'lg' }
6161
]}
6262
name={`radio1-${index}`}
6363
/>
@@ -66,9 +66,9 @@ const sections = [
6666
<ComponentWrapper title="Preselected option">
6767
<section.component
6868
items={[
69-
{ label: 'Small' },
70-
{ label: 'Medium', selected: true },
71-
{ label: 'Large' }
69+
{ label: 'Small', value: 'sm' },
70+
{ label: 'Medium', selected: true, value: 'md' },
71+
{ label: 'Large', value: 'lg' }
7272
]}
7373
name={`radio2-${index}`}
7474
/>
@@ -77,9 +77,9 @@ const sections = [
7777
<ComponentWrapper title="Disabled option">
7878
<section.component
7979
items={[
80-
{ label: 'Small' },
81-
{ label: 'Medium', selected: true, disabled: true },
82-
{ label: 'Large', disabled: true }
80+
{ label: 'Small', value: 'sm' },
81+
{ label: 'Medium', selected: true, disabled: true, value: 'md' },
82+
{ label: 'Large', disabled: true, value: 'lg' }
8383
]}
8484
name={`radio3-${index}`}
8585
/>
@@ -88,9 +88,9 @@ const sections = [
8888
<ComponentWrapper title="Options with subtext and link">
8989
<section.component
9090
items={[
91-
{ label: 'Starter', subText: 'For getting started' },
92-
{ label: 'Standard', subText: 'For existing small <a href="/" target="_blank">businesses</a>' },
93-
{ label: 'Premium', subText: 'For enterprise solutions' }
91+
{ label: 'Starter', subText: 'For getting started', value: 'starter' },
92+
{ label: 'Standard', subText: 'For existing small <a href="/" target="_blank">businesses</a>', value: 'standard' },
93+
{ label: 'Premium', subText: 'For enterprise solutions', value: 'premium' }
9494
]}
9595
name={`radio4-${index}`}
9696
/>
@@ -99,9 +99,9 @@ const sections = [
9999
<ComponentWrapper title="With custom color">
100100
<section.component
101101
items={[
102-
{ label: 'Small' },
103-
{ label: 'Medium' },
104-
{ label: 'Large' }
102+
{ label: 'Small', value: 'sm' },
103+
{ label: 'Medium', value: 'md' },
104+
{ label: 'Large', value: 'lg' }
105105
]}
106106
color="#1dd1a1"
107107
name={`radio5-${index}`}
@@ -111,9 +111,9 @@ const sections = [
111111
<ComponentWrapper title="With inline display">
112112
<section.component
113113
items={[
114-
{ label: 'Small' },
115-
{ label: 'Medium' },
116-
{ label: 'Large' }
114+
{ label: 'Small', value: 'sm' },
115+
{ label: 'Medium', value: 'md' },
116+
{ label: 'Large', value: 'lg' }
117117
]}
118118
inline={true}
119119
name={`radio6-${index}`}

src/pages/react.astro

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
import Layout from '@static/Layout.astro'
3+
import ReactPlayground from '@playground/ReactPlayground.tsx'
4+
---
5+
6+
<Layout>
7+
<h1>React Playground</h1>
8+
<h2>For interactive elements</h2>
9+
<ReactPlayground client:load />
10+
</Layout>

src/pages/svelte.astro

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
import Layout from '@static/Layout.astro'
3+
import SveltePlayground from '@playground/SveltePlayground.svelte'
4+
---
5+
6+
<Layout>
7+
<h1>Svelte Playground</h1>
8+
<h2>For interactive elements</h2>
9+
<SveltePlayground client:load />
10+
</Layout>

src/playground/ReactPlayground.tsx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React from 'react'
2+
3+
import Card from '@components/Card/Card.tsx'
4+
import Accordion from '@components/Accordion/Accordion.tsx'
5+
import Badge from '@components/Badge/Badge.tsx'
6+
import Button from '@components/Button/Button.tsx'
7+
import Checkbox from '@components/Checkbox/Checkbox.tsx'
8+
import Radio from '@components/Radio/Radio.tsx'
9+
import Switch from '@components/Switch/Switch.tsx'
10+
11+
const ReactPlayground = () => {
12+
return (
13+
<div className="grid md-2 lg-3">
14+
<Card title="Accordion">
15+
<Accordion items={[{
16+
title: 'Do you offer support?',
17+
content: 'We provide 30 days of support.'
18+
}, {
19+
title: 'Can I request customizations?',
20+
content: 'Yes!'
21+
}]} />
22+
</Card>
23+
24+
<Card title="Badge">
25+
<Badge onClick={() => console.log('👋')}>Click me</Badge>
26+
</Card>
27+
28+
<Card title="Button">
29+
<Button onClick={() => console.log('👋')} theme="alert">
30+
Click me
31+
</Button>
32+
</Card>
33+
34+
<Card title="Checkbox">
35+
<Checkbox
36+
label="Accept"
37+
onClick={e => console.log(`checked: ${e.target.checked}`)}
38+
/>
39+
</Card>
40+
41+
<Card title="Radio">
42+
<Radio
43+
items={[
44+
{ label: 'Small', value: 'sm' },
45+
{ label: 'Medium', value: 'md' },
46+
{ label: 'Large', value: 'lg' }
47+
]}
48+
name="radio"
49+
onChange={e => console.log('changed to:', e.target.value)}
50+
/>
51+
</Card>
52+
53+
<Card title="Switch">
54+
<Switch
55+
onClick={e => console.log(`switched: ${e.target.checked}`)}
56+
/>
57+
</Card>
58+
</div>
59+
)
60+
61+
}
62+
63+
export default ReactPlayground

0 commit comments

Comments
 (0)