@nuralyui/radio-group 0.0.9 → 0.0.10
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.
- package/bundle.js +317 -2
- package/package.json +1 -1
package/bundle.js
CHANGED
|
@@ -28,10 +28,325 @@ import{css as t,LitElement as r,html as i,nothing as o}from"lit";import{property
|
|
|
28
28
|
* @license
|
|
29
29
|
* Copyright 2023 Nuraly, Laabidi Aymen
|
|
30
30
|
* SPDX-License-Identifier: MIT
|
|
31
|
-
*/const y=t
|
|
31
|
+
*/const y=t`
|
|
32
|
+
:host {
|
|
33
|
+
/* ========================================
|
|
34
|
+
* CSS CUSTOM PROPERTIES - RADIO GROUP
|
|
35
|
+
* ======================================== */
|
|
36
|
+
|
|
37
|
+
/* Group Layout */
|
|
38
|
+
--nuraly-radio-group-gap: 12px;
|
|
39
|
+
--nuraly-radio-group-horizontal-gap: 16px;
|
|
40
|
+
|
|
41
|
+
/* Colors - Error/Warning states */
|
|
42
|
+
--nuraly-radio-group-error-icon-color: var(--nuraly-color-radio-error-icon, #ef4444);
|
|
43
|
+
--nuraly-radio-group-error-text-color: var(--nuraly-color-radio-error-text, #ef4444);
|
|
44
|
+
--nuraly-radio-group-warning-icon-color: var(--nuraly-color-radio-warning-icon, #f59e0b);
|
|
45
|
+
--nuraly-radio-group-warning-text-color: var(--nuraly-color-radio-warning-text, #f59e0b);
|
|
46
|
+
|
|
47
|
+
/* Typography */
|
|
48
|
+
--nuraly-radio-group-font-family: var(--nuraly-font-family-radio, Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif);
|
|
49
|
+
--nuraly-radio-group-message-font-size: var(--nuraly-font-size-radio-message, 12px);
|
|
50
|
+
|
|
51
|
+
/* Button type styling */
|
|
52
|
+
--nuraly-radio-group-button-border-radius: 4px;
|
|
53
|
+
--nuraly-radio-group-button-hover-color: var(--nuraly-color-radio-border-hover, #7c3aed);
|
|
54
|
+
|
|
55
|
+
/* Slot container styling */
|
|
56
|
+
--nuraly-radio-group-slot-hover-bg: rgba(124, 58, 237, 0.04);
|
|
57
|
+
--nuraly-radio-group-slot-selected-bg: rgba(124, 58, 237, 0.08);
|
|
58
|
+
--nuraly-radio-group-slot-border-radius: 6px;
|
|
59
|
+
|
|
60
|
+
/* ========================================
|
|
61
|
+
* COMPONENT STYLES
|
|
62
|
+
* ======================================== */
|
|
63
|
+
|
|
64
|
+
width: fit-content;
|
|
65
|
+
display: block;
|
|
66
|
+
font-family: var(--nuraly-radio-group-font-family);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* ========================================
|
|
70
|
+
* RADIO GROUP LAYOUT
|
|
71
|
+
* ======================================== */
|
|
72
|
+
|
|
73
|
+
.radio-group {
|
|
74
|
+
display: flex;
|
|
75
|
+
flex-direction: column;
|
|
76
|
+
gap: var(--nuraly-radio-group-gap);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.radio-group.horizontal {
|
|
80
|
+
flex-direction: row;
|
|
81
|
+
flex-wrap: wrap;
|
|
82
|
+
gap: var(--nuraly-radio-group-horizontal-gap);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.radio-wrapper {
|
|
86
|
+
display: flex;
|
|
87
|
+
flex-direction: column;
|
|
88
|
+
gap: 4px;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* ========================================
|
|
92
|
+
* MESSAGE CONTAINERS (Error/Warning)
|
|
93
|
+
* ======================================== */
|
|
94
|
+
|
|
95
|
+
.radio-wrapper .message-container {
|
|
96
|
+
display: flex;
|
|
97
|
+
align-items: center;
|
|
98
|
+
gap: 6px;
|
|
99
|
+
font-size: var(--nuraly-radio-group-message-font-size);
|
|
100
|
+
padding-left: 28px; /* Align with radio label */
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
nr-icon {
|
|
104
|
+
display: flex;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.radio-wrapper.error nr-icon {
|
|
108
|
+
--nuraly-icon-color: var(--nuraly-radio-group-error-icon-color);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.radio-wrapper.warning nr-icon {
|
|
112
|
+
--nuraly-icon-color: var(--nuraly-radio-group-warning-icon-color);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.radio-wrapper.error .message-container {
|
|
116
|
+
color: var(--nuraly-radio-group-error-text-color);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.radio-wrapper.warning .message-container {
|
|
120
|
+
color: var(--nuraly-radio-group-warning-text-color);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/* ========================================
|
|
124
|
+
* BUTTON TYPE STYLING
|
|
125
|
+
* ======================================== */
|
|
126
|
+
|
|
127
|
+
.type-button {
|
|
128
|
+
display: inline-flex;
|
|
129
|
+
gap: 0px;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/* Button border radius for first and last child */
|
|
133
|
+
.type-button :first-child {
|
|
134
|
+
--nuraly-button-border-top-left-radius: var(--nuraly-radio-group-button-border-radius);
|
|
135
|
+
--nuraly-button-border-bottom-left-radius: var(--nuraly-radio-group-button-border-radius);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.type-button :last-child {
|
|
139
|
+
--nuraly-button-border-top-right-radius: var(--nuraly-radio-group-button-border-radius);
|
|
140
|
+
--nuraly-button-border-bottom-right-radius: var(--nuraly-radio-group-button-border-radius);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.type-button nr-button:not(:last-child) {
|
|
144
|
+
margin-right: -1px;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.type-button nr-button {
|
|
148
|
+
position: relative;
|
|
149
|
+
z-index: 1;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.type-button nr-button[type="default"]:hover {
|
|
153
|
+
--nuraly-button-color: var(--nuraly-radio-group-button-hover-color);
|
|
154
|
+
--nuraly-button-border-color: var(--nuraly-radio-group-button-hover-color);
|
|
155
|
+
z-index: 2;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.type-button nr-button[type="primary"] {
|
|
159
|
+
z-index: 1;
|
|
160
|
+
position: relative;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/* Disabled button states */
|
|
164
|
+
.type-button nr-button[disabled] {
|
|
165
|
+
opacity: 0.6;
|
|
166
|
+
cursor: not-allowed;
|
|
167
|
+
pointer-events: none;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.type-button nr-button[disabled]:hover {
|
|
171
|
+
z-index: auto;
|
|
172
|
+
--nuraly-button-border-color: var(--nuraly-button-disabled-border-color, var(--nuraly-button-local-disabled-border-color));
|
|
173
|
+
--nuraly-button-background-color: var(--nuraly-button-disabled-background-color, var(--nuraly-button-local-disabled-background-color));
|
|
174
|
+
--nuraly-button-color: var(--nuraly-button-disabled-text-color, var(--nuraly-button-local-disabled-text-color));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.type-button nr-button[type="primary"][disabled] {
|
|
178
|
+
--nuraly-button-background-color: var(--nuraly-button-primary-disabled-background-color, var(--nuraly-button-local-primary-disabled-background-color));
|
|
179
|
+
--nuraly-button-border-color: var(--nuraly-button-primary-disabled-border-color, var(--nuraly-button-local-primary-disabled-border-color));
|
|
180
|
+
--nuraly-button-color: var(--nuraly-button-primary-disabled-text-color, var(--nuraly-button-local-primary-disabled-text-color));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.type-button nr-button[type="primary"][disabled] nr-icon {
|
|
184
|
+
--nuraly-icon-color: var(--nuraly-button-primary-disabled-text-color, var(--nuraly-button-local-primary-disabled-text-color));
|
|
185
|
+
--nuraly-icon-local-color: var(--nuraly-button-primary-disabled-text-color, var(--nuraly-button-local-primary-disabled-text-color));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/* ========================================
|
|
189
|
+
* SLOT-BASED RADIO STYLING
|
|
190
|
+
* ======================================== */
|
|
191
|
+
|
|
192
|
+
.slot-wrapper {
|
|
193
|
+
display: flex;
|
|
194
|
+
align-items: flex-start;
|
|
195
|
+
gap: 12px;
|
|
196
|
+
cursor: pointer;
|
|
197
|
+
transition: all 0.2s ease;
|
|
198
|
+
padding: 8px;
|
|
199
|
+
border-radius: var(--nuraly-radio-group-slot-border-radius);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.slot-wrapper:hover {
|
|
203
|
+
background-color: var(--nuraly-radio-group-slot-hover-bg);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.slot-wrapper nr-radio {
|
|
207
|
+
flex-shrink: 0;
|
|
208
|
+
margin-top: 2px;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.slot-wrapper .slot-content {
|
|
212
|
+
flex: 1;
|
|
213
|
+
min-width: 0;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.slot-container.selected .slot-wrapper {
|
|
217
|
+
background-color: var(--nuraly-radio-group-slot-selected-bg);
|
|
218
|
+
}
|
|
219
|
+
`;var g,v,f,m,$;!function(t){t.Horizontal="horizontal",t.Vertical="vertical"}(g||(g={})),function(t){t.Left="left",t.Right="right"}(v||(v={})),function(t){t.Default="default",t.Button="button",t.Slot="slot"}(f||(f={})),function(t){t.Small="small",t.Medium="medium",t.Large="large"}(m||(m={})),function(t){t.Default="default",t.Solid="solid"}($||($={}));
|
|
32
220
|
/**
|
|
33
221
|
* @license
|
|
34
222
|
* Copyright 2023 Nuraly, Laabidi Aymen
|
|
35
223
|
* SPDX-License-Identifier: MIT
|
|
36
224
|
*/
|
|
37
|
-
var x=function(t,r,i,o){for(var e,s=arguments.length,n=s<3?r:null===o?o=Object.getOwnPropertyDescriptor(r,i):o,a=t.length-1;a>=0;a--)(e=t[a])&&(n=(s<3?e(n):s>3?e(r,i,n):e(r,i))||n);return s>3&&n&&Object.defineProperty(r,i,n),n};let w=class extends(l(r)){constructor(){super(...arguments),this.requiredComponents=["nr-icon","nr-radio"],this.options=[],this.defaultValue="",this.value="",this.name="radioGroup",this.direction="vertical",this.type=
|
|
225
|
+
var x=function(t,r,i,o){for(var e,s=arguments.length,n=s<3?r:null===o?o=Object.getOwnPropertyDescriptor(r,i):o,a=t.length-1;a>=0;a--)(e=t[a])&&(n=(s<3?e(n):s>3?e(r,i,n):e(r,i))||n);return s>3&&n&&Object.defineProperty(r,i,n),n};let w=class extends(l(r)){constructor(){super(...arguments),this.requiredComponents=["nr-icon","nr-radio"],this.options=[],this.defaultValue="",this.value="",this.name="radioGroup",this.direction="vertical",this.type=f.Default,this.required=!1,this.disabled=!1,this.size="medium",this.position="left",this.groupController=new u(this),this.keyboardController=new c(this,this.groupController),this.focusController=new h(this),this.validationController=new p(this),this.rippleController=new b(this)}get selectedOption(){return this.groupController.getSelectedOption()}isOptionSelected(t){return this.groupController.isOptionSelected(t)}isOptionDisabled(t){return this.groupController.isOptionDisabled(t)}handleSelectionChange(t){this.groupController.selectOption(t)}setFocusedOption(t){this.focusController.setFocusedOption(t)}handleKeyDown(t){}addRippleEffect(t){this.rippleController.addRippleEffect(t)}validate(){return this.validationController.validate()}get validationMessage(){return this.validationController.validationMessage}get isValid(){return this.validationController.isValid}getFormData(){return this.validationController.getFormData()}reset(){this.validationController.reset()}get formData(){return this.validationController.getFormDataObject()}checkValidity(){return this.validate()}reportValidity(){return this.validationController.reportValidity()}focus(){this.focusController.focus()}blur(){this.focusController.blur()}renderOptionDefault(){return i`
|
|
226
|
+
<div
|
|
227
|
+
role="radiogroup"
|
|
228
|
+
aria-labelledby="radio-group-label"
|
|
229
|
+
class="radio-group ${this.direction}"
|
|
230
|
+
>
|
|
231
|
+
${this.options.map(((t,r)=>i`
|
|
232
|
+
<div
|
|
233
|
+
class="${a({"radio-wrapper":!0,error:"error"===t.state,warning:"warning"===t.state,[t.className||""]:Boolean(t.className)})}"
|
|
234
|
+
data-theme="${this.currentTheme}"
|
|
235
|
+
style="${t.style||""}"
|
|
236
|
+
title="${t.title||""}"
|
|
237
|
+
>
|
|
238
|
+
<nr-radio
|
|
239
|
+
id="${t.id||t.value}"
|
|
240
|
+
name="${this.name}"
|
|
241
|
+
value="${t.value}"
|
|
242
|
+
size="${this.size}"
|
|
243
|
+
?checked="${this.isOptionSelected(t)}"
|
|
244
|
+
?disabled="${this.isOptionDisabled(t)||this.disabled}"
|
|
245
|
+
?required="${this.required}"
|
|
246
|
+
tabindex="${this.isOptionSelected(t)?"0":"-1"}"
|
|
247
|
+
@change="${r=>{this.addRippleEffect(r),this.handleSelectionChange(t)}}"
|
|
248
|
+
@focus="${()=>this.setFocusedOption(r)}"
|
|
249
|
+
>
|
|
250
|
+
${t.label}
|
|
251
|
+
</nr-radio>
|
|
252
|
+
${t.state&&t.message?i`<div class="message-container" id="${t.value}-message">
|
|
253
|
+
<nr-icon name="${"error"===t.state?"exclamation-circle":"warning"}"></nr-icon>
|
|
254
|
+
<span>${t.message}</span>
|
|
255
|
+
</div>`:o}
|
|
256
|
+
</div>
|
|
257
|
+
`))}
|
|
258
|
+
</div>
|
|
259
|
+
`}renderOptionsWithButtons(){return i`
|
|
260
|
+
<div
|
|
261
|
+
class="type-button"
|
|
262
|
+
role="radiogroup"
|
|
263
|
+
aria-labelledby="radio-group-label"
|
|
264
|
+
@keydown="${this.handleKeyDown}"
|
|
265
|
+
>
|
|
266
|
+
${this.options.map(((t,r)=>i`
|
|
267
|
+
<nr-button
|
|
268
|
+
class="${this.isOptionSelected(t)?"selected":""}"
|
|
269
|
+
type="${this.isOptionSelected(t)?"primary":"default"}"
|
|
270
|
+
role="radio"
|
|
271
|
+
aria-checked="${this.isOptionSelected(t)}"
|
|
272
|
+
aria-describedby="${t.state&&t.message?`${t.value}-message`:o}"
|
|
273
|
+
tabindex="${this.isOptionSelected(t)?"0":"-1"}"
|
|
274
|
+
.icon="${t.icon?[t.icon]:[]}"
|
|
275
|
+
.disabled="${this.isOptionDisabled(t)}"
|
|
276
|
+
@click="${()=>this.handleSelectionChange(t)}"
|
|
277
|
+
@focus="${()=>this.setFocusedOption(r)}"
|
|
278
|
+
>
|
|
279
|
+
${t.label}
|
|
280
|
+
</nr-button>
|
|
281
|
+
${t.state&&t.message?i`<div class="message-container" id="${t.value}-message">
|
|
282
|
+
<nr-icon name="${"error"===t.state?"exclamation-circle":"warning"}"></nr-icon>
|
|
283
|
+
<span>${t.message}</span>
|
|
284
|
+
</div>`:o}
|
|
285
|
+
`))}
|
|
286
|
+
</div>
|
|
287
|
+
`}renderOptionsWithSlots(){return i`
|
|
288
|
+
<div
|
|
289
|
+
role="radiogroup"
|
|
290
|
+
aria-labelledby="radio-group-label"
|
|
291
|
+
class="radio-group slot-group ${this.direction}"
|
|
292
|
+
>
|
|
293
|
+
${this.options.map(((t,r)=>i`
|
|
294
|
+
<div
|
|
295
|
+
class="${a({"radio-wrapper":!0,"slot-container":!0,error:"error"===t.state,warning:"warning"===t.state,selected:this.isOptionSelected(t),[t.className||""]:Boolean(t.className)})}"
|
|
296
|
+
data-theme="${this.currentTheme}"
|
|
297
|
+
style="${t.style||""}"
|
|
298
|
+
title="${t.title||""}"
|
|
299
|
+
>
|
|
300
|
+
<div class="slot-wrapper" @click="${()=>this.handleSelectionChange(t)}">
|
|
301
|
+
<nr-radio
|
|
302
|
+
id="${t.id||t.value}"
|
|
303
|
+
name="${this.name}"
|
|
304
|
+
value="${t.value}"
|
|
305
|
+
size="${this.size}"
|
|
306
|
+
?checked="${this.isOptionSelected(t)}"
|
|
307
|
+
?disabled="${this.isOptionDisabled(t)||this.disabled}"
|
|
308
|
+
?required="${this.required}"
|
|
309
|
+
tabindex="${this.isOptionSelected(t)?"0":"-1"}"
|
|
310
|
+
@change="${r=>{this.addRippleEffect(r),this.handleSelectionChange(t)}}"
|
|
311
|
+
@focus="${()=>this.setFocusedOption(r)}"
|
|
312
|
+
>
|
|
313
|
+
</nr-radio>
|
|
314
|
+
<div class="slot-content">
|
|
315
|
+
<slot name="${t.value}"></slot>
|
|
316
|
+
</div>
|
|
317
|
+
</div>
|
|
318
|
+
${t.state&&t.message?i`<div class="message-container" id="${t.value}-message">
|
|
319
|
+
<nr-icon name="${"error"===t.state?"exclamation-circle":"warning"}"></nr-icon>
|
|
320
|
+
<span>${t.message}</span>
|
|
321
|
+
</div>`:o}
|
|
322
|
+
</div>
|
|
323
|
+
`))}
|
|
324
|
+
</div>
|
|
325
|
+
`}renderButtonsWithSlots(){return i`
|
|
326
|
+
<div
|
|
327
|
+
class="type-button"
|
|
328
|
+
role="radiogroup"
|
|
329
|
+
aria-labelledby="radio-group-label"
|
|
330
|
+
@keydown="${this.handleKeyDown}"
|
|
331
|
+
>
|
|
332
|
+
${this.options.map(((t,r)=>i`
|
|
333
|
+
<nr-button
|
|
334
|
+
class="${this.isOptionSelected(t)?"selected":""}"
|
|
335
|
+
type="${this.isOptionSelected(t)?"primary":"default"}"
|
|
336
|
+
role="radio"
|
|
337
|
+
aria-checked="${this.isOptionSelected(t)}"
|
|
338
|
+
aria-describedby="${t.state&&t.message?`${t.value}-message`:o}"
|
|
339
|
+
tabindex="${this.isOptionSelected(t)?"0":"-1"}"
|
|
340
|
+
.disabled="${this.isOptionDisabled(t)}"
|
|
341
|
+
@click="${()=>this.handleSelectionChange(t)}"
|
|
342
|
+
@focus="${()=>this.setFocusedOption(r)}"
|
|
343
|
+
>
|
|
344
|
+
<slot name="${t.value}" slot="default"></slot>
|
|
345
|
+
</nr-button>
|
|
346
|
+
${t.state&&t.message?i`<div class="message-container" id="${t.value}-message">
|
|
347
|
+
<nr-icon name="${"error"===t.state?"exclamation-circle":"warning"}"></nr-icon>
|
|
348
|
+
<span>${t.message}</span>
|
|
349
|
+
</div>`:o}
|
|
350
|
+
`))}
|
|
351
|
+
</div>
|
|
352
|
+
`}render(){return i`${n(this.type,[[f.Default,()=>this.renderOptionDefault()],[f.Button,()=>this.renderOptionsWithButtons()],[f.Slot,()=>this.renderOptionsWithSlots()],["button-slot",()=>this.renderButtonsWithSlots()]])} `}};w.styles=y,x([e({type:Array})],w.prototype,"options",void 0),x([e({type:String,attribute:"default-value"})],w.prototype,"defaultValue",void 0),x([e({type:String})],w.prototype,"value",void 0),x([e({type:String})],w.prototype,"name",void 0),x([e({type:String})],w.prototype,"direction",void 0),x([e({type:String})],w.prototype,"type",void 0),x([e({type:Boolean})],w.prototype,"required",void 0),x([e({type:Boolean})],w.prototype,"disabled",void 0),x([e({type:String})],w.prototype,"size",void 0),x([e({type:String})],w.prototype,"position",void 0),w=x([s("nr-radio-group")],w);export{w as NrRadioGroupElement,g as RadioButtonDirection,v as RadioButtonPosition,m as RadioButtonSize,f as RadioButtonType,$ as RadioButtonVariant};
|