@bwui/vue 0.0.0-stage → 0.1.2

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.
@@ -0,0 +1,256 @@
1
+ import { defineComponent, h, type PropType } from 'vue'
2
+ import { cn } from './cn'
3
+
4
+ type ButtonVariant =
5
+ | 'primary'
6
+ | 'secondary'
7
+ | 'outline'
8
+ | 'ghost'
9
+ | 'danger'
10
+ | 'solid'
11
+ type ButtonSize = 'sm' | 'md' | 'lg'
12
+
13
+ export const Button = defineComponent({
14
+ name: 'BwButton',
15
+ props: {
16
+ variant: { type: String as PropType<ButtonVariant>, default: 'primary' },
17
+ size: { type: String as PropType<ButtonSize>, default: 'md' },
18
+ type: { type: String as PropType<'button' | 'submit' | 'reset'>, default: 'button' },
19
+ },
20
+ setup(props, { slots, attrs }) {
21
+ return () =>
22
+ h(
23
+ 'button',
24
+ {
25
+ ...attrs,
26
+ type: props.type,
27
+ class: cn(
28
+ 'bw-btn',
29
+ `bw-btn--${props.variant}`,
30
+ props.size !== 'md' && `bw-btn--${props.size}`,
31
+ String(attrs.class || ''),
32
+ ),
33
+ },
34
+ slots.default?.(),
35
+ )
36
+ },
37
+ })
38
+
39
+ export const ButtonLink = defineComponent({
40
+ name: 'BwButtonLink',
41
+ props: {
42
+ href: { type: String, required: true },
43
+ variant: { type: String as PropType<ButtonVariant>, default: 'primary' },
44
+ size: { type: String as PropType<ButtonSize>, default: 'md' },
45
+ },
46
+ setup(props, { slots, attrs }) {
47
+ return () =>
48
+ h(
49
+ 'a',
50
+ {
51
+ ...attrs,
52
+ href: props.href,
53
+ class: cn(
54
+ 'bw-btn',
55
+ `bw-btn--${props.variant}`,
56
+ props.size !== 'md' && `bw-btn--${props.size}`,
57
+ String(attrs.class || ''),
58
+ ),
59
+ },
60
+ slots.default?.(),
61
+ )
62
+ },
63
+ })
64
+
65
+ export const Badge = defineComponent({
66
+ name: 'BwBadge',
67
+ props: {
68
+ variant: { type: String, default: 'default' },
69
+ },
70
+ setup(props, { slots, attrs }) {
71
+ return () =>
72
+ h(
73
+ 'span',
74
+ { ...attrs, class: cn('bw-badge', `bw-badge--${props.variant}`, String(attrs.class || '')) },
75
+ slots.default?.(),
76
+ )
77
+ },
78
+ })
79
+
80
+ export const Card = defineComponent({
81
+ name: 'BwCard',
82
+ setup(_, { slots, attrs }) {
83
+ return () => h('div', { ...attrs, class: cn('bw-card', String(attrs.class || '')) }, slots.default?.())
84
+ },
85
+ })
86
+
87
+ export const Alert = defineComponent({
88
+ name: 'BwAlert',
89
+ props: { variant: { type: String, default: 'default' } },
90
+ setup(props, { slots, attrs }) {
91
+ return () =>
92
+ h(
93
+ 'div',
94
+ {
95
+ ...attrs,
96
+ role: 'alert',
97
+ class: cn(
98
+ 'bw-alert',
99
+ props.variant !== 'default' && `bw-alert--${props.variant}`,
100
+ String(attrs.class || ''),
101
+ ),
102
+ },
103
+ slots.default?.(),
104
+ )
105
+ },
106
+ })
107
+
108
+ function div(name: string, className: string) {
109
+ return defineComponent({
110
+ name,
111
+ setup(_, { slots, attrs }) {
112
+ return () =>
113
+ h('div', { ...attrs, class: cn(className, String(attrs.class || '')) }, slots.default?.())
114
+ },
115
+ })
116
+ }
117
+
118
+ export const Stack = div('BwStack', 'bw-stack')
119
+ export const Cluster = div('BwCluster', 'bw-cluster')
120
+ export const Grid = div('BwGrid', 'bw-grid')
121
+ export const Container = div('BwContainer', 'bw-container')
122
+ export const Field = div('BwField', 'bw-field')
123
+ export const FormActions = div('BwFormActions', 'bw-form__actions bw-cluster')
124
+
125
+ export const Form = defineComponent({
126
+ name: 'BwForm',
127
+ setup(_, { slots, attrs }) {
128
+ return () =>
129
+ h('form', { ...attrs, class: cn('bw-form', 'bw-stack', String(attrs.class || '')) }, slots.default?.())
130
+ },
131
+ })
132
+
133
+ export const Label = defineComponent({
134
+ name: 'BwLabel',
135
+ setup(_, { slots, attrs }) {
136
+ return () =>
137
+ h('label', { ...attrs, class: cn('bw-field__label', String(attrs.class || '')) }, slots.default?.())
138
+ },
139
+ })
140
+
141
+ export const Hint = defineComponent({
142
+ name: 'BwHint',
143
+ setup(_, { slots, attrs }) {
144
+ return () =>
145
+ h('p', { ...attrs, class: cn('bw-field__hint', String(attrs.class || '')) }, slots.default?.())
146
+ },
147
+ })
148
+
149
+ export const FieldError = defineComponent({
150
+ name: 'BwFieldError',
151
+ setup(_, { slots, attrs }) {
152
+ return () =>
153
+ h('p', { ...attrs, class: cn('bw-field__error', String(attrs.class || '')) }, slots.default?.())
154
+ },
155
+ })
156
+
157
+ export const Input = defineComponent({
158
+ name: 'BwInput',
159
+ inheritAttrs: false,
160
+ setup(_, { attrs }) {
161
+ return () => h('input', { ...attrs, class: cn('bw-input', String(attrs.class || '')) })
162
+ },
163
+ })
164
+
165
+ export const Textarea = defineComponent({
166
+ name: 'BwTextarea',
167
+ inheritAttrs: false,
168
+ setup(_, { attrs }) {
169
+ return () => h('textarea', { ...attrs, class: cn('bw-textarea', String(attrs.class || '')) })
170
+ },
171
+ })
172
+
173
+ export const Select = defineComponent({
174
+ name: 'BwSelect',
175
+ inheritAttrs: false,
176
+ setup(_, { slots, attrs }) {
177
+ return () =>
178
+ h('select', { ...attrs, class: cn('bw-select', String(attrs.class || '')) }, slots.default?.())
179
+ },
180
+ })
181
+
182
+ export const Checkbox = defineComponent({
183
+ name: 'BwCheckbox',
184
+ inheritAttrs: false,
185
+ setup(_, { attrs }) {
186
+ return () =>
187
+ h('input', { ...attrs, type: 'checkbox', class: cn('bw-checkbox', String(attrs.class || '')) })
188
+ },
189
+ })
190
+
191
+ export const Radio = defineComponent({
192
+ name: 'BwRadio',
193
+ inheritAttrs: false,
194
+ setup(_, { attrs }) {
195
+ return () =>
196
+ h('input', { ...attrs, type: 'radio', class: cn('bw-radio', String(attrs.class || '')) })
197
+ },
198
+ })
199
+
200
+ export const TimeInput = defineComponent({
201
+ name: 'BwTimeInput',
202
+ inheritAttrs: false,
203
+ setup(_, { attrs }) {
204
+ return () =>
205
+ h('input', { ...attrs, type: 'time', class: cn('bw-input', String(attrs.class || '')) })
206
+ },
207
+ })
208
+
209
+ export const DateTimeInput = defineComponent({
210
+ name: 'BwDateTimeInput',
211
+ inheritAttrs: false,
212
+ setup(_, { attrs }) {
213
+ return () =>
214
+ h('input', {
215
+ ...attrs,
216
+ type: 'datetime-local',
217
+ class: cn('bw-input', String(attrs.class || '')),
218
+ })
219
+ },
220
+ })
221
+
222
+ export const SkipLink = defineComponent({
223
+ name: 'BwSkipLink',
224
+ props: { href: { type: String, default: '#main' } },
225
+ setup(props, { slots, attrs }) {
226
+ return () =>
227
+ h(
228
+ 'a',
229
+ { ...attrs, href: props.href, class: cn('bw-skip-link', String(attrs.class || '')) },
230
+ slots.default?.() ?? 'Skip to content',
231
+ )
232
+ },
233
+ })
234
+
235
+ export const ThemeToggle = defineComponent({
236
+ name: 'BwThemeToggle',
237
+ setup(_, { attrs }) {
238
+ return () =>
239
+ h(
240
+ 'button',
241
+ {
242
+ ...attrs,
243
+ type: 'button',
244
+ class: cn('bw-btn', 'bw-btn--ghost', String(attrs.class || '')),
245
+ 'data-bw-theme-toggle': '',
246
+ onClick: () => {
247
+ const root = document.body
248
+ const next = root.getAttribute('data-theme') === 'dark' ? 'light' : 'dark'
249
+ root.setAttribute('data-theme', next)
250
+ document.documentElement.setAttribute('data-theme', next)
251
+ },
252
+ },
253
+ 'Theme',
254
+ )
255
+ },
256
+ })