@aristobyte-ui/radio 1.0.112 → 2.1.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.
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ import './Radio.scss';
3
+ export var Radio = function (_a) {
4
+ var children = _a.children, value = _a.value, checked = _a.checked, name = _a.name, _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.highlightLabel, highlightLabel = _c === void 0 ? false : _c, _d = _a.size, size = _d === void 0 ? 'md' : _d, _e = _a.variant, variant = _e === void 0 ? 'default' : _e, _f = _a.appearance, appearance = _f === void 0 ? 'default' : _f, _g = _a.alignLabel, alignLabel = _g === void 0 ? 'right' : _g, onChange = _a.onChange, _h = _a.className, className = _h === void 0 ? '' : _h, _j = _a.style, style = _j === void 0 ? {} : _j;
5
+ var handleChange = function () {
6
+ if (!disabled && onChange) {
7
+ onChange(value);
8
+ }
9
+ };
10
+ return (React.createElement("label", { className: "radio ".concat("radio-align-label--".concat(alignLabel), " ").concat("radio-appearance--".concat(appearance), " ").concat("radio-variant--".concat(variant), " ").concat("radio-size--".concat(size), " ").concat(disabled ? 'radio--disabled' : '', " ").concat(className), style: style },
11
+ React.createElement("input", { type: "radio", name: name, value: value, checked: checked, disabled: disabled, onChange: handleChange, className: "radio__input" }),
12
+ React.createElement("span", { className: "radio__control" }),
13
+ children && (React.createElement("span", { className: "radio__label ".concat(highlightLabel ? 'radio__label--highlight-label' : '') }, children))));
14
+ };
@@ -0,0 +1,15 @@
1
+ @use "@aristobyte-ui/utils/styles/settings" as *;
2
+
3
+ .radio-group {
4
+ display: flex;
5
+ gap: 20px;
6
+ min-width: max-content;
7
+
8
+ &--horizontal {
9
+ flex-direction: row;
10
+ }
11
+
12
+ &--vertical {
13
+ flex-direction: column;
14
+ }
15
+ }
@@ -0,0 +1,48 @@
1
+ 'use client';
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
29
+ import * as React from 'react';
30
+ import { Radio } from '../Radio';
31
+ import './RadioGroup.scss';
32
+ export var RadioGroup = function (_a) {
33
+ var name = _a.name, value = _a.value, onChange = _a.onChange, children = _a.children, _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.highlightLabel, highlightLabel = _c === void 0 ? false : _c, _d = _a.size, size = _d === void 0 ? 'md' : _d, _e = _a.variant, variant = _e === void 0 ? 'default' : _e, _f = _a.appearance, appearance = _f === void 0 ? 'outline' : _f, _g = _a.align, align = _g === void 0 ? 'horizontal' : _g, _h = _a.alignLabel, alignLabel = _h === void 0 ? 'right' : _h, _j = _a.className, className = _j === void 0 ? '' : _j, _k = _a.style, style = _k === void 0 ? {} : _k;
34
+ var uniqueId = React.useId();
35
+ var _l = __read(React.useState(value), 2), currentValue = _l[0], setCurrentValue = _l[1];
36
+ var radios = React.Children.toArray(children).filter(function (child) { return React.isValidElement(child) && child.type === Radio; });
37
+ var handleChange = function (currentRadioValue) {
38
+ if (onChange) {
39
+ onChange(currentRadioValue);
40
+ }
41
+ setCurrentValue(currentRadioValue);
42
+ };
43
+ return (React.createElement("div", { key: uniqueId, className: "radio-group ".concat("radio-group--".concat(align), " ").concat(className), style: style }, radios.map(function (_a) {
44
+ var _b, _c, _d, _e, _f, _g;
45
+ var props = _a.props;
46
+ return (React.createElement(Radio, __assign({}, props, { key: "".concat(name, "-").concat(props.value, "-").concat(uniqueId), name: "".concat(name, "-").concat(props.value, "-").concat(uniqueId), checked: props.value === currentValue, onChange: function () { return handleChange(props.value); }, disabled: (_b = props.disabled) !== null && _b !== void 0 ? _b : disabled, size: (_c = props.size) !== null && _c !== void 0 ? _c : size, variant: (_d = props.variant) !== null && _d !== void 0 ? _d : variant, appearance: (_e = props.appearance) !== null && _e !== void 0 ? _e : appearance, highlightLabel: (_f = props.highlightLabel) !== null && _f !== void 0 ? _f : highlightLabel, alignLabel: (_g = props.alignLabel) !== null && _g !== void 0 ? _g : alignLabel })));
47
+ })));
48
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./Radio";
2
+ export * from "./RadioGroup";
@@ -0,0 +1 @@
1
+ export * from './components';