@semcore/radio 4.2.5 → 5.0.1
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/CHANGELOG.md +19 -0
- package/lib/cjs/Radio.js +19 -34
- package/lib/cjs/Radio.js.map +1 -1
- package/lib/cjs/index.d.ts +76 -0
- package/lib/cjs/style/radio.shadow.css +28 -29
- package/lib/es6/Radio.js +19 -33
- package/lib/es6/Radio.js.map +1 -1
- package/lib/es6/index.d.ts +76 -0
- package/lib/es6/style/radio.shadow.css +28 -29
- package/lib/types/index.d.ts +3 -1
- package/package.json +6 -3
- package/src/Radio.jsx +4 -16
- package/src/index.d.ts +3 -1
- package/src/style/radio.shadow.css +28 -29
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
CHANGELOG.md standards are inspired by [keepachangelog.com](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
|
5
|
+
## [5.0.1] - 2022-05-19
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Updated Intergalactic internal dependencies to the latest.
|
|
10
|
+
|
|
11
|
+
## [5.0.0] - 2022-05-17
|
|
12
|
+
|
|
13
|
+
### BREAK
|
|
14
|
+
|
|
15
|
+
- Updated styles according to the library redesign policy.
|
|
16
|
+
- Remove value "xl" for "size".
|
|
17
|
+
|
|
18
|
+
## [4.2.6] - 2022-03-21
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- Version patch update due to children dependencies update (`@semcore/typography` [3.4.1 ~> 3.4.2]).
|
|
23
|
+
|
|
5
24
|
## [4.2.5] - 2022-03-14
|
|
6
25
|
|
|
7
26
|
### Changed
|
package/lib/cjs/Radio.js
CHANGED
|
@@ -37,8 +37,6 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
37
37
|
|
|
38
38
|
var _flexBox = require("@semcore/flex-box");
|
|
39
39
|
|
|
40
|
-
var _typography = require("@semcore/typography");
|
|
41
|
-
|
|
42
40
|
var _assignProps5 = _interopRequireDefault(require("@semcore/utils/lib/assignProps"));
|
|
43
41
|
|
|
44
42
|
var _keyboardFocusEnhance = _interopRequireDefault(require("@semcore/utils/lib/enhances/keyboardFocusEnhance"));
|
|
@@ -64,30 +62,24 @@ var style = (
|
|
|
64
62
|
/*__reshadow_css_start__*/
|
|
65
63
|
_core.sstyled.insert(
|
|
66
64
|
/*__inner_css_start__*/
|
|
67
|
-
".
|
|
65
|
+
".___SRadio_1rk58_gg_{display:inline-flex;align-items:flex-start;cursor:pointer}.___SRadio_1rk58_gg_.__disabled_1rk58_gg_{opacity:0.3;cursor:default;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.___SText_1rk58_gg_{margin-left:8px}.___SText_1rk58_gg_._size_m_1rk58_gg_{font-size:14px;line-height:1.42}.___SText_1rk58_gg_._size_l_1rk58_gg_{font-size:16px;line-height:1.5}.___SValue_1rk58_gg_{position:relative;flex-shrink:0;padding:0;outline:none;z-index:0;margin-top:2px}.___SValue_1rk58_gg_:before{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;background:#fff;border:1px solid;border-radius:50%}.___SValue_1rk58_gg_:after{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;margin:auto;width:0;height:0;border-radius:50%;background:#fff}.___SValue_1rk58_gg_._size_m_1rk58_gg_{width:16px;height:16px}.___SValue_1rk58_gg_._size_l_1rk58_gg_{width:20px;height:20px}.___SValue_1rk58_gg_._state_normal_1rk58_gg_:before{border-color:#c4c7cf}.___SValue_1rk58_gg_._state_invalid_1rk58_gg_:before{border-color:#ff4953}.___SControl_1rk58_gg_{position:absolute;clip:rect(1px,1px,1px,1px)}.___SControl_1rk58_gg_:checked~.___SValue_1rk58_gg_:before{border-color:#008ff8;background-color:#008ff8}.___SControl_1rk58_gg_:checked~.___SValue_1rk58_gg_._size_m_1rk58_gg_:after{width:6px;height:6px}.___SControl_1rk58_gg_:checked~.___SValue_1rk58_gg_._size_l_1rk58_gg_:after{width:8px;height:8px}.___SValue_1rk58_gg_._state_normal_1rk58_gg_.__keyboardFocused_1rk58_gg_:before{box-shadow:0 0 0 3px rgba(0, 143, 248, 0.2);border-color:#008ff8}.___SValue_1rk58_gg_._state_invalid_1rk58_gg_.__keyboardFocused_1rk58_gg_:before{box-shadow:0px 0px 0px 3px rgba(255, 73, 83, 0.2)}.___SControl_1rk58_gg_:checked~.___SValue_1rk58_gg_.__theme_1rk58_gg_:before{border-color:var(--theme_1uqy20u);background-color:var(--theme_1uqy20u)}.___SValue_1rk58_gg_._state_normal_1rk58_gg_.__theme_1rk58_gg_:before{border-color:var(--theme_1uqy20u)}"
|
|
68
66
|
/*__inner_css_end__*/
|
|
69
|
-
, "
|
|
67
|
+
, "1uqy20u_gg_")
|
|
70
68
|
/*__reshadow_css_end__*/
|
|
71
69
|
, {
|
|
72
|
-
"__SRadio": "
|
|
73
|
-
"_disabled": "
|
|
74
|
-
"__SText": "
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"--theme": "--theme_ahqhbl"
|
|
70
|
+
"__SRadio": "___SRadio_1rk58_gg_",
|
|
71
|
+
"_disabled": "__disabled_1rk58_gg_",
|
|
72
|
+
"__SText": "___SText_1rk58_gg_",
|
|
73
|
+
"_size_m": "_size_m_1rk58_gg_",
|
|
74
|
+
"_size_l": "_size_l_1rk58_gg_",
|
|
75
|
+
"__SValue": "___SValue_1rk58_gg_",
|
|
76
|
+
"_state_normal": "_state_normal_1rk58_gg_",
|
|
77
|
+
"_state_invalid": "_state_invalid_1rk58_gg_",
|
|
78
|
+
"__SControl": "___SControl_1rk58_gg_",
|
|
79
|
+
"_keyboardFocused": "__keyboardFocused_1rk58_gg_",
|
|
80
|
+
"_theme": "__theme_1rk58_gg_",
|
|
81
|
+
"--theme": "--theme_1uqy20u"
|
|
85
82
|
});
|
|
86
|
-
var SIZE_TEXT_MAP = {
|
|
87
|
-
xl: 300,
|
|
88
|
-
l: 200,
|
|
89
|
-
m: 100
|
|
90
|
-
};
|
|
91
83
|
|
|
92
84
|
var RadioGroupRoot = /*#__PURE__*/function (_Component) {
|
|
93
85
|
(0, _inherits2["default"])(RadioGroupRoot, _Component);
|
|
@@ -201,13 +193,13 @@ var Radio = /*#__PURE__*/function (_Component2) {
|
|
|
201
193
|
size = _assignProps4$size === void 0 ? 'm' : _assignProps4$size;
|
|
202
194
|
|
|
203
195
|
return {
|
|
204
|
-
size:
|
|
196
|
+
size: size
|
|
205
197
|
};
|
|
206
198
|
}
|
|
207
199
|
}, {
|
|
208
200
|
key: "render",
|
|
209
201
|
value: function render() {
|
|
210
|
-
var _ref = this
|
|
202
|
+
var _ref = this.asProps,
|
|
211
203
|
_ref3;
|
|
212
204
|
|
|
213
205
|
var SRadio = _flexBox.Box;
|
|
@@ -256,7 +248,6 @@ var Value = /*#__PURE__*/function (_Component3) {
|
|
|
256
248
|
forwardRef = _this$asProps3.forwardRef,
|
|
257
249
|
styles = _this$asProps3.styles,
|
|
258
250
|
includeInputProps = _this$asProps3.includeInputProps,
|
|
259
|
-
state = _this$asProps3.state,
|
|
260
251
|
theme = _this$asProps3.theme;
|
|
261
252
|
|
|
262
253
|
var _getInputProps = (0, _inputProps["default"])(this.asProps, includeInputProps),
|
|
@@ -264,18 +255,12 @@ var Value = /*#__PURE__*/function (_Component3) {
|
|
|
264
255
|
controlProps = _getInputProps2[0],
|
|
265
256
|
boxProps = _getInputProps2[1];
|
|
266
257
|
|
|
267
|
-
var color = '';
|
|
268
|
-
|
|
269
|
-
if (theme && state !== 'invalid') {
|
|
270
|
-
color = (0, _color["default"])(theme);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
258
|
return _ref4 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(SControl, _ref4.cn("SControl", _objectSpread({
|
|
274
259
|
"tag": "input",
|
|
275
260
|
"type": "radio"
|
|
276
261
|
}, controlProps))), /*#__PURE__*/_react["default"].createElement(SValue, _ref4.cn("SValue", _objectSpread({
|
|
277
262
|
"ref": forwardRef,
|
|
278
|
-
"use:theme":
|
|
263
|
+
"use:theme": (0, _color["default"])(theme)
|
|
279
264
|
}, boxProps))));
|
|
280
265
|
}
|
|
281
266
|
}]);
|
|
@@ -290,10 +275,10 @@ var Value = /*#__PURE__*/function (_Component3) {
|
|
|
290
275
|
(0, _defineProperty2["default"])(Value, "hoistProps", ['disabled']);
|
|
291
276
|
|
|
292
277
|
function Text(props) {
|
|
293
|
-
var _ref2 =
|
|
278
|
+
var _ref2 = arguments[0],
|
|
294
279
|
_ref5;
|
|
295
280
|
|
|
296
|
-
var SText =
|
|
281
|
+
var SText = _flexBox.Box;
|
|
297
282
|
var styles = props.styles;
|
|
298
283
|
return _ref5 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SText, _ref5.cn("SText", _objectSpread({}, (0, _core.assignProps)({}, _ref2))));
|
|
299
284
|
}
|
package/lib/cjs/Radio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Radio.jsx"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../src/Radio.jsx"],"names":["RadioGroupRoot","value","asProps","theme","size","name","onChange","Children","Component","state","defaultValue","RadioGroup","Radio","checked","e","context","props","other","undefined","bindHandlerChange","SRadio","Box","styles","style","CONTEXT_COMPONENT","Value","target","SValue","SControl","forwardRef","includeInputProps","controlProps","boxProps","inputProps","defaultChecked","Text","SText"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AADA;;AAEA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAIMA,c;;;;;;;;;;;;WASJ,6BAAoB;AAClB,a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A;;AACP,UAAMc,MAAM,GAAGN,YAAf;AACA,UAAMO,QAAQ,GAAGP,YAAjB;AACA,2BAAyD,KAAKnB,OAA9D;AAAA,UAAQ2B,UAAR,kBAAQA,UAAR;AAAA,UAAoBP,MAApB,kBAAoBA,MAApB;AAAA,UAA4BQ,iBAA5B,kBAA4BA,iBAA5B;AAAA,UAA+C3B,KAA/C,kBAA+CA,KAA/C;;AAEA,2BAAiC,4BAAc,KAAKD,OAAnB,EAA4B4B,iBAA5B,CAAjC;AAAA;AAAA,UAAOC,YAAP;AAAA,UAAqBC,QAArB;;AAEA,qBAAO,mBAAQV,MAAR,CAAP,eACE,+EACE,gCAAC,QAAD;AAAA,eAAc,OAAd;AAAA,gBAA2B;AAA3B,SAAuCS,YAAvC,GADF,eAEE,gCAAC,MAAD;AAAA,eAAaF,UAAb;AAAA,qBAAoC,uBAAa1B,KAAb;AAApC,SAA6D6B,QAA7D,GAFF,CADF;AAMD;;;EA3BiBxB,e;;iCAAdiB,K,kBACkB;AACpBK,EAAAA,iBAAiB,EAAEG,sBADC;AAEpBC,EAAAA,cAAc,EAAE;AAFI,C;iCADlBT,K,aAKa,CAAC,uCAAD,C;iCALbA,K,gBAMgB,CAAC,UAAD,C;;AAwBtB,SAASU,IAAT,CAAcnB,KAAd,EAAqB;AAAA;AAAA;;AACnB,MAAMoB,KAAK,GAE2Bf,YAFtC;AACA,MAAQC,MAAR,GAAmBN,KAAnB,CAAQM,MAAR;AACA,iBAAO,mBAAQA,MAAR,CAAP,eAAuB,gCAAC,KAAD,0EAAvB;AACD;;eAGc,sBAAgBV,KAAhB,EAAuB;AACpCa,EAAAA,KAAK,EAALA,KADoC;AAEpCU,EAAAA,IAAI,EAAJA;AAFoC,CAAvB,C","sourcesContent":["import React from 'react';\nimport createComponent, { Component, CONTEXT_COMPONENT, sstyled, Root } from '@semcore/core';\nimport { Box } from '@semcore/flex-box';\nimport assignProps from '@semcore/utils/lib/assignProps';\nimport keyboardFocusEnhance from '@semcore/utils/lib/enhances/keyboardFocusEnhance';\nimport resolveColor from '@semcore/utils/lib/color';\nimport getInputProps, { inputProps } from '@semcore/utils/lib/inputProps';\n\nimport style from './style/radio.shadow.css';\n\nclass RadioGroupRoot extends Component {\n static displayName = 'RadioGroup';\n\n static defaultProps = {\n state: 'normal',\n size: 'm',\n defaultValue: null,\n };\n\n uncontrolledProps() {\n return {\n value: null,\n };\n }\n\n setContext() {\n const { theme, size, name, value, onChange } = this.asProps;\n return {\n onChange,\n value,\n theme,\n size,\n name,\n };\n }\n\n render() {\n const { Children } = this.asProps;\n return <Children />;\n }\n}\n\nconst RadioGroup = createComponent(RadioGroupRoot);\n\nclass Radio extends Component {\n static displayName = 'Radio';\n static style = style;\n static contextType = RadioGroup[CONTEXT_COMPONENT];\n\n bindHandlerChange = (value) => (checked, e) => {\n this.context.onChange(value, e);\n };\n\n getValueProps(props) {\n // The default values are here, since you cannot rewrite out of context\n const { state = 'normal', size = 'm', theme, name } = assignProps(this.props, this.context);\n const { value } = this.context;\n const other = {};\n // if used with the context\n if (value !== undefined) {\n other['checked'] = value === props.value;\n other['onChange'] = this.bindHandlerChange(props.value);\n }\n return {\n ...other,\n state,\n size,\n theme,\n name,\n };\n }\n\n getTextProps() {\n // The default values are here, since you cannot rewrite out of context\n const { size = 'm' } = assignProps(this.props, this.context);\n return {\n size: size,\n };\n }\n\n render() {\n const SRadio = Root;\n const { styles, Children } = this.asProps;\n\n return sstyled(styles)(\n <SRadio render={Box} tag=\"label\">\n <Children />\n </SRadio>,\n );\n }\n}\n\nclass Value extends Component {\n static defaultProps = {\n includeInputProps: inputProps,\n defaultChecked: false,\n };\n static enhance = [keyboardFocusEnhance()];\n static hoistProps = ['disabled'];\n\n uncontrolledProps() {\n return {\n checked: (e) => e.target.checked,\n };\n }\n\n render() {\n const SValue = Box;\n const SControl = Box;\n const { forwardRef, styles, includeInputProps, theme } = this.asProps;\n\n const [controlProps, boxProps] = getInputProps(this.asProps, includeInputProps);\n\n return sstyled(styles)(\n <>\n <SControl tag=\"input\" type=\"radio\" {...controlProps} />\n <SValue ref={forwardRef} use:theme={resolveColor(theme)} {...boxProps} />\n </>,\n );\n }\n}\n\nfunction Text(props) {\n const SText = Root;\n const { styles } = props;\n return sstyled(styles)(<SText render={Box} />);\n}\n\nexport { inputProps, RadioGroup };\nexport default createComponent(Radio, {\n Value,\n Text,\n});\n"],"file":"Radio.js"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { CProps, PropGetterFn, ReturnEl } from '@semcore/core';
|
|
2
|
+
import { IBoxProps, IFlexProps } from '@semcore/flex-box';
|
|
3
|
+
import { IKeyboardFocusProps } from '@semcore/utils/lib/enhances/keyboardFocusEnhance';
|
|
4
|
+
import { Text } from '@semcore/typography';
|
|
5
|
+
|
|
6
|
+
export type RadioSize = 'm' | 'l';
|
|
7
|
+
export type RadioState = 'normal' | 'invalid';
|
|
8
|
+
export type RadioValue = string | number | boolean;
|
|
9
|
+
|
|
10
|
+
export interface IRadioProps extends IFlexProps {
|
|
11
|
+
/**
|
|
12
|
+
* The value displaying the state of the component
|
|
13
|
+
* @default normal
|
|
14
|
+
*/
|
|
15
|
+
state?: RadioState;
|
|
16
|
+
/**
|
|
17
|
+
* Radio button size
|
|
18
|
+
* @default m
|
|
19
|
+
**/
|
|
20
|
+
size?: RadioSize;
|
|
21
|
+
/** The theme of the radio button that you can send your color to */
|
|
22
|
+
theme?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface IRadioGroupProps {
|
|
26
|
+
/** Radio group name */
|
|
27
|
+
name?: string;
|
|
28
|
+
/** Active default value */
|
|
29
|
+
defaultValue?: RadioValue;
|
|
30
|
+
/** Active value */
|
|
31
|
+
value?: RadioValue;
|
|
32
|
+
/** Called when the selected element is changed */
|
|
33
|
+
onChange?: (value: RadioValue, e?: React.SyntheticEvent<HTMLInputElement>) => void;
|
|
34
|
+
/** Radio button size */
|
|
35
|
+
size?: RadioSize;
|
|
36
|
+
/** The theme of the radio button that you can send your color to */
|
|
37
|
+
theme?: string;
|
|
38
|
+
/** Blocks access and changes to the form field */
|
|
39
|
+
disabled?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface IRadioValueProps extends IBoxProps, IKeyboardFocusProps {
|
|
43
|
+
/** List of elements that can be put on a hidden input */
|
|
44
|
+
includeInputProps?: string[];
|
|
45
|
+
/**
|
|
46
|
+
* The value displaying the state of the component
|
|
47
|
+
* @default normal
|
|
48
|
+
*/
|
|
49
|
+
state?: RadioState;
|
|
50
|
+
/** The theme of the radio button that you can send your color to */
|
|
51
|
+
theme?: string;
|
|
52
|
+
/** Radio button size */
|
|
53
|
+
size?: RadioSize;
|
|
54
|
+
/** The element value is required for RadioGroup */
|
|
55
|
+
value?: RadioValue;
|
|
56
|
+
/** Called when the value changes */
|
|
57
|
+
onChange?: (value: boolean, e?: React.SyntheticEvent<HTMLInputElement>) => void;
|
|
58
|
+
/** Blocks access and changes to the form field */
|
|
59
|
+
disabled?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface IRadioCtx {
|
|
63
|
+
getValueProps: PropGetterFn;
|
|
64
|
+
getTextProps: PropGetterFn;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare const RadioGroup: <T>(props: CProps<IRadioGroupProps & T>) => ReturnEl;
|
|
68
|
+
|
|
69
|
+
export { RadioGroup };
|
|
70
|
+
|
|
71
|
+
declare const Radio: (<T>(props: CProps<IRadioProps & T, IRadioCtx>) => ReturnEl) & {
|
|
72
|
+
Value: <T>(props: IRadioValueProps & T) => ReturnEl;
|
|
73
|
+
Text: typeof Text;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export default Radio;
|
|
@@ -17,14 +17,25 @@ SText {
|
|
|
17
17
|
margin-left: 8px;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
SText[size='m'] {
|
|
21
|
+
font-size: var(--fs-200);
|
|
22
|
+
line-height: var(--lh-200);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
SText[size='l'] {
|
|
26
|
+
font-size: var(--fs-300);
|
|
27
|
+
line-height: var(--lh-300);
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
SValue {
|
|
21
31
|
position: relative;
|
|
22
32
|
flex-shrink: 0;
|
|
23
|
-
margin: 0;
|
|
24
33
|
padding: 0;
|
|
25
34
|
outline: none;
|
|
26
35
|
z-index: 0;
|
|
27
36
|
|
|
37
|
+
margin-top: 2px;
|
|
38
|
+
|
|
28
39
|
&::before {
|
|
29
40
|
content: '';
|
|
30
41
|
position: absolute;
|
|
@@ -52,30 +63,22 @@ SValue {
|
|
|
52
63
|
}
|
|
53
64
|
}
|
|
54
65
|
|
|
55
|
-
SValue[size='
|
|
56
|
-
margin-top: 2px;
|
|
57
|
-
width: 20px;
|
|
58
|
-
height: 20px;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
SValue[size='l'] {
|
|
62
|
-
margin-top: 1px;
|
|
66
|
+
SValue[size='m'] {
|
|
63
67
|
width: 16px;
|
|
64
68
|
height: 16px;
|
|
65
69
|
}
|
|
66
70
|
|
|
67
|
-
SValue[size='
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
height: 12px;
|
|
71
|
+
SValue[size='l'] {
|
|
72
|
+
width: 20px;
|
|
73
|
+
height: 20px;
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
SValue[state='normal']::before {
|
|
74
|
-
border-color: var(--
|
|
77
|
+
border-color: var(--gray-200);
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
SValue[state='invalid']::before {
|
|
78
|
-
border-color: var(--
|
|
81
|
+
border-color: var(--red-400);
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
SControl {
|
|
@@ -84,38 +87,34 @@ SControl {
|
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
SControl:checked ~ SValue::before {
|
|
87
|
-
border-color: var(--
|
|
88
|
-
background-color: var(--
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
SControl:checked ~ SValue[size='xl']::after {
|
|
92
|
-
width: 8px;
|
|
93
|
-
height: 8px;
|
|
90
|
+
border-color: var(--blue-400);
|
|
91
|
+
background-color: var(--blue-400);
|
|
94
92
|
}
|
|
95
93
|
|
|
96
|
-
SControl:checked ~ SValue[size='
|
|
94
|
+
SControl:checked ~ SValue[size='m']::after {
|
|
97
95
|
width: 6px;
|
|
98
96
|
height: 6px;
|
|
99
97
|
}
|
|
100
98
|
|
|
101
|
-
SControl:checked ~ SValue[size='
|
|
102
|
-
width:
|
|
103
|
-
height:
|
|
99
|
+
SControl:checked ~ SValue[size='l']::after {
|
|
100
|
+
width: 8px;
|
|
101
|
+
height: 8px;
|
|
104
102
|
}
|
|
105
103
|
|
|
106
104
|
SValue[state='normal'][keyboardFocused]::before {
|
|
107
|
-
box-shadow: var(--
|
|
108
|
-
border-color: var(--
|
|
105
|
+
box-shadow: var(--keyboard-focus);
|
|
106
|
+
border-color: var(--blue-400);
|
|
109
107
|
}
|
|
110
108
|
|
|
111
109
|
SValue[state='invalid'][keyboardFocused]::before {
|
|
112
|
-
box-shadow:
|
|
110
|
+
box-shadow: var(--keyboard-focus-invalid);
|
|
113
111
|
}
|
|
114
112
|
|
|
115
113
|
SControl:checked ~ SValue[theme]::before {
|
|
116
114
|
border-color: var(--theme);
|
|
117
115
|
background-color: var(--theme);
|
|
118
116
|
}
|
|
117
|
+
|
|
119
118
|
SValue[state='normal'][theme]::before {
|
|
120
119
|
border-color: var(--theme);
|
|
121
120
|
}
|
package/lib/es6/Radio.js
CHANGED
|
@@ -21,7 +21,6 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
21
21
|
import React from 'react';
|
|
22
22
|
import createComponent, { Component, CONTEXT_COMPONENT, sstyled, Root } from '@semcore/core';
|
|
23
23
|
import { Box } from '@semcore/flex-box';
|
|
24
|
-
import { Text as TypographyText } from '@semcore/typography';
|
|
25
24
|
import assignProps from '@semcore/utils/lib/assignProps';
|
|
26
25
|
import keyboardFocusEnhance from '@semcore/utils/lib/enhances/keyboardFocusEnhance';
|
|
27
26
|
import resolveColor from '@semcore/utils/lib/color';
|
|
@@ -32,30 +31,24 @@ var style = (
|
|
|
32
31
|
/*__reshadow_css_start__*/
|
|
33
32
|
_sstyled.insert(
|
|
34
33
|
/*__inner_css_start__*/
|
|
35
|
-
".
|
|
34
|
+
".___SRadio_1rk58_gg_{display:inline-flex;align-items:flex-start;cursor:pointer}.___SRadio_1rk58_gg_.__disabled_1rk58_gg_{opacity:0.3;cursor:default;pointer-events:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.___SText_1rk58_gg_{margin-left:8px}.___SText_1rk58_gg_._size_m_1rk58_gg_{font-size:14px;line-height:1.42}.___SText_1rk58_gg_._size_l_1rk58_gg_{font-size:16px;line-height:1.5}.___SValue_1rk58_gg_{position:relative;flex-shrink:0;padding:0;outline:none;z-index:0;margin-top:2px}.___SValue_1rk58_gg_:before{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;background:#fff;border:1px solid;border-radius:50%}.___SValue_1rk58_gg_:after{content:\"\";position:absolute;top:0;left:0;right:0;bottom:0;margin:auto;width:0;height:0;border-radius:50%;background:#fff}.___SValue_1rk58_gg_._size_m_1rk58_gg_{width:16px;height:16px}.___SValue_1rk58_gg_._size_l_1rk58_gg_{width:20px;height:20px}.___SValue_1rk58_gg_._state_normal_1rk58_gg_:before{border-color:#c4c7cf}.___SValue_1rk58_gg_._state_invalid_1rk58_gg_:before{border-color:#ff4953}.___SControl_1rk58_gg_{position:absolute;clip:rect(1px,1px,1px,1px)}.___SControl_1rk58_gg_:checked~.___SValue_1rk58_gg_:before{border-color:#008ff8;background-color:#008ff8}.___SControl_1rk58_gg_:checked~.___SValue_1rk58_gg_._size_m_1rk58_gg_:after{width:6px;height:6px}.___SControl_1rk58_gg_:checked~.___SValue_1rk58_gg_._size_l_1rk58_gg_:after{width:8px;height:8px}.___SValue_1rk58_gg_._state_normal_1rk58_gg_.__keyboardFocused_1rk58_gg_:before{box-shadow:0 0 0 3px rgba(0, 143, 248, 0.2);border-color:#008ff8}.___SValue_1rk58_gg_._state_invalid_1rk58_gg_.__keyboardFocused_1rk58_gg_:before{box-shadow:0px 0px 0px 3px rgba(255, 73, 83, 0.2)}.___SControl_1rk58_gg_:checked~.___SValue_1rk58_gg_.__theme_1rk58_gg_:before{border-color:var(--theme_1uqy20u);background-color:var(--theme_1uqy20u)}.___SValue_1rk58_gg_._state_normal_1rk58_gg_.__theme_1rk58_gg_:before{border-color:var(--theme_1uqy20u)}"
|
|
36
35
|
/*__inner_css_end__*/
|
|
37
|
-
, "
|
|
36
|
+
, "1uqy20u_gg_")
|
|
38
37
|
/*__reshadow_css_end__*/
|
|
39
38
|
, {
|
|
40
|
-
"__SRadio": "
|
|
41
|
-
"_disabled": "
|
|
42
|
-
"__SText": "
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"--theme": "--theme_ahqhbl"
|
|
39
|
+
"__SRadio": "___SRadio_1rk58_gg_",
|
|
40
|
+
"_disabled": "__disabled_1rk58_gg_",
|
|
41
|
+
"__SText": "___SText_1rk58_gg_",
|
|
42
|
+
"_size_m": "_size_m_1rk58_gg_",
|
|
43
|
+
"_size_l": "_size_l_1rk58_gg_",
|
|
44
|
+
"__SValue": "___SValue_1rk58_gg_",
|
|
45
|
+
"_state_normal": "_state_normal_1rk58_gg_",
|
|
46
|
+
"_state_invalid": "_state_invalid_1rk58_gg_",
|
|
47
|
+
"__SControl": "___SControl_1rk58_gg_",
|
|
48
|
+
"_keyboardFocused": "__keyboardFocused_1rk58_gg_",
|
|
49
|
+
"_theme": "__theme_1rk58_gg_",
|
|
50
|
+
"--theme": "--theme_1uqy20u"
|
|
53
51
|
});
|
|
54
|
-
var SIZE_TEXT_MAP = {
|
|
55
|
-
xl: 300,
|
|
56
|
-
l: 200,
|
|
57
|
-
m: 100
|
|
58
|
-
};
|
|
59
52
|
|
|
60
53
|
var RadioGroupRoot = /*#__PURE__*/function (_Component) {
|
|
61
54
|
_inherits(RadioGroupRoot, _Component);
|
|
@@ -174,13 +167,13 @@ var Radio = /*#__PURE__*/function (_Component2) {
|
|
|
174
167
|
size = _assignProps4$size === void 0 ? 'm' : _assignProps4$size;
|
|
175
168
|
|
|
176
169
|
return {
|
|
177
|
-
size:
|
|
170
|
+
size: size
|
|
178
171
|
};
|
|
179
172
|
}
|
|
180
173
|
}, {
|
|
181
174
|
key: "render",
|
|
182
175
|
value: function render() {
|
|
183
|
-
var _ref = this
|
|
176
|
+
var _ref = this.asProps,
|
|
184
177
|
_ref3;
|
|
185
178
|
|
|
186
179
|
var SRadio = Box;
|
|
@@ -233,7 +226,6 @@ var Value = /*#__PURE__*/function (_Component3) {
|
|
|
233
226
|
forwardRef = _this$asProps3.forwardRef,
|
|
234
227
|
styles = _this$asProps3.styles,
|
|
235
228
|
includeInputProps = _this$asProps3.includeInputProps,
|
|
236
|
-
state = _this$asProps3.state,
|
|
237
229
|
theme = _this$asProps3.theme;
|
|
238
230
|
|
|
239
231
|
var _getInputProps = getInputProps(this.asProps, includeInputProps),
|
|
@@ -241,18 +233,12 @@ var Value = /*#__PURE__*/function (_Component3) {
|
|
|
241
233
|
controlProps = _getInputProps2[0],
|
|
242
234
|
boxProps = _getInputProps2[1];
|
|
243
235
|
|
|
244
|
-
var color = '';
|
|
245
|
-
|
|
246
|
-
if (theme && state !== 'invalid') {
|
|
247
|
-
color = resolveColor(theme);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
236
|
return _ref4 = sstyled(styles), /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SControl, _ref4.cn("SControl", _objectSpread({
|
|
251
237
|
"tag": "input",
|
|
252
238
|
"type": "radio"
|
|
253
239
|
}, controlProps))), /*#__PURE__*/React.createElement(SValue, _ref4.cn("SValue", _objectSpread({
|
|
254
240
|
"ref": forwardRef,
|
|
255
|
-
"use:theme":
|
|
241
|
+
"use:theme": resolveColor(theme)
|
|
256
242
|
}, boxProps))));
|
|
257
243
|
}
|
|
258
244
|
}]);
|
|
@@ -270,10 +256,10 @@ _defineProperty(Value, "enhance", [keyboardFocusEnhance()]);
|
|
|
270
256
|
_defineProperty(Value, "hoistProps", ['disabled']);
|
|
271
257
|
|
|
272
258
|
function Text(props) {
|
|
273
|
-
var _ref2 =
|
|
259
|
+
var _ref2 = arguments[0],
|
|
274
260
|
_ref5;
|
|
275
261
|
|
|
276
|
-
var SText =
|
|
262
|
+
var SText = Box;
|
|
277
263
|
var styles = props.styles;
|
|
278
264
|
return _ref5 = sstyled(styles), /*#__PURE__*/React.createElement(SText, _ref5.cn("SText", _objectSpread({}, _assignProps2({}, _ref2))));
|
|
279
265
|
}
|
package/lib/es6/Radio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Radio.jsx"],"names":["React","createComponent","Component","CONTEXT_COMPONENT","sstyled","Root","Box","
|
|
1
|
+
{"version":3,"sources":["../../src/Radio.jsx"],"names":["React","createComponent","Component","CONTEXT_COMPONENT","sstyled","Root","Box","assignProps","keyboardFocusEnhance","resolveColor","getInputProps","inputProps","RadioGroupRoot","value","asProps","theme","size","name","onChange","Children","state","defaultValue","RadioGroup","Radio","checked","e","context","props","other","undefined","bindHandlerChange","SRadio","styles","style","Value","target","SValue","SControl","forwardRef","includeInputProps","controlProps","boxProps","defaultChecked","Text","SText"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,eAAP,IAA0BC,SAA1B,EAAqCC,iBAArC,EAAwDC,OAAxD,EAAiEC,IAAjE,QAA6E,eAA7E;AACA,SAASC,GAAT,QAAoB,mBAApB;AACA,OAAOC,WAAP,MAAwB,gCAAxB;AACA,OAAOC,o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SAASrB,UAAT,EAAqBW,UAArB;AACA,eAAerB,eAAe,CAACsB,KAAD,EAAQ;AACpCW,EAAAA,KAAK,EAALA,KADoC;AAEpCS,EAAAA,IAAI,EAAJA;AAFoC,CAAR,CAA9B","sourcesContent":["import React from 'react';\nimport createComponent, { Component, CONTEXT_COMPONENT, sstyled, Root } from '@semcore/core';\nimport { Box } from '@semcore/flex-box';\nimport assignProps from '@semcore/utils/lib/assignProps';\nimport keyboardFocusEnhance from '@semcore/utils/lib/enhances/keyboardFocusEnhance';\nimport resolveColor from '@semcore/utils/lib/color';\nimport getInputProps, { inputProps } from '@semcore/utils/lib/inputProps';\n\nimport style from './style/radio.shadow.css';\n\nclass RadioGroupRoot extends Component {\n static displayName = 'RadioGroup';\n\n static defaultProps = {\n state: 'normal',\n size: 'm',\n defaultValue: null,\n };\n\n uncontrolledProps() {\n return {\n value: null,\n };\n }\n\n setContext() {\n const { theme, size, name, value, onChange } = this.asProps;\n return {\n onChange,\n value,\n theme,\n size,\n name,\n };\n }\n\n render() {\n const { Children } = this.asProps;\n return <Children />;\n }\n}\n\nconst RadioGroup = createComponent(RadioGroupRoot);\n\nclass Radio extends Component {\n static displayName = 'Radio';\n static style = style;\n static contextType = RadioGroup[CONTEXT_COMPONENT];\n\n bindHandlerChange = (value) => (checked, e) => {\n this.context.onChange(value, e);\n };\n\n getValueProps(props) {\n // The default values are here, since you cannot rewrite out of context\n const { state = 'normal', size = 'm', theme, name } = assignProps(this.props, this.context);\n const { value } = this.context;\n const other = {};\n // if used with the context\n if (value !== undefined) {\n other['checked'] = value === props.value;\n other['onChange'] = this.bindHandlerChange(props.value);\n }\n return {\n ...other,\n state,\n size,\n theme,\n name,\n };\n }\n\n getTextProps() {\n // The default values are here, since you cannot rewrite out of context\n const { size = 'm' } = assignProps(this.props, this.context);\n return {\n size: size,\n };\n }\n\n render() {\n const SRadio = Root;\n const { styles, Children } = this.asProps;\n\n return sstyled(styles)(\n <SRadio render={Box} tag=\"label\">\n <Children />\n </SRadio>,\n );\n }\n}\n\nclass Value extends Component {\n static defaultProps = {\n includeInputProps: inputProps,\n defaultChecked: false,\n };\n static enhance = [keyboardFocusEnhance()];\n static hoistProps = ['disabled'];\n\n uncontrolledProps() {\n return {\n checked: (e) => e.target.checked,\n };\n }\n\n render() {\n const SValue = Box;\n const SControl = Box;\n const { forwardRef, styles, includeInputProps, theme } = this.asProps;\n\n const [controlProps, boxProps] = getInputProps(this.asProps, includeInputProps);\n\n return sstyled(styles)(\n <>\n <SControl tag=\"input\" type=\"radio\" {...controlProps} />\n <SValue ref={forwardRef} use:theme={resolveColor(theme)} {...boxProps} />\n </>,\n );\n }\n}\n\nfunction Text(props) {\n const SText = Root;\n const { styles } = props;\n return sstyled(styles)(<SText render={Box} />);\n}\n\nexport { inputProps, RadioGroup };\nexport default createComponent(Radio, {\n Value,\n Text,\n});\n"],"file":"Radio.js"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { CProps, PropGetterFn, ReturnEl } from '@semcore/core';
|
|
2
|
+
import { IBoxProps, IFlexProps } from '@semcore/flex-box';
|
|
3
|
+
import { IKeyboardFocusProps } from '@semcore/utils/lib/enhances/keyboardFocusEnhance';
|
|
4
|
+
import { Text } from '@semcore/typography';
|
|
5
|
+
|
|
6
|
+
export type RadioSize = 'm' | 'l';
|
|
7
|
+
export type RadioState = 'normal' | 'invalid';
|
|
8
|
+
export type RadioValue = string | number | boolean;
|
|
9
|
+
|
|
10
|
+
export interface IRadioProps extends IFlexProps {
|
|
11
|
+
/**
|
|
12
|
+
* The value displaying the state of the component
|
|
13
|
+
* @default normal
|
|
14
|
+
*/
|
|
15
|
+
state?: RadioState;
|
|
16
|
+
/**
|
|
17
|
+
* Radio button size
|
|
18
|
+
* @default m
|
|
19
|
+
**/
|
|
20
|
+
size?: RadioSize;
|
|
21
|
+
/** The theme of the radio button that you can send your color to */
|
|
22
|
+
theme?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface IRadioGroupProps {
|
|
26
|
+
/** Radio group name */
|
|
27
|
+
name?: string;
|
|
28
|
+
/** Active default value */
|
|
29
|
+
defaultValue?: RadioValue;
|
|
30
|
+
/** Active value */
|
|
31
|
+
value?: RadioValue;
|
|
32
|
+
/** Called when the selected element is changed */
|
|
33
|
+
onChange?: (value: RadioValue, e?: React.SyntheticEvent<HTMLInputElement>) => void;
|
|
34
|
+
/** Radio button size */
|
|
35
|
+
size?: RadioSize;
|
|
36
|
+
/** The theme of the radio button that you can send your color to */
|
|
37
|
+
theme?: string;
|
|
38
|
+
/** Blocks access and changes to the form field */
|
|
39
|
+
disabled?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface IRadioValueProps extends IBoxProps, IKeyboardFocusProps {
|
|
43
|
+
/** List of elements that can be put on a hidden input */
|
|
44
|
+
includeInputProps?: string[];
|
|
45
|
+
/**
|
|
46
|
+
* The value displaying the state of the component
|
|
47
|
+
* @default normal
|
|
48
|
+
*/
|
|
49
|
+
state?: RadioState;
|
|
50
|
+
/** The theme of the radio button that you can send your color to */
|
|
51
|
+
theme?: string;
|
|
52
|
+
/** Radio button size */
|
|
53
|
+
size?: RadioSize;
|
|
54
|
+
/** The element value is required for RadioGroup */
|
|
55
|
+
value?: RadioValue;
|
|
56
|
+
/** Called when the value changes */
|
|
57
|
+
onChange?: (value: boolean, e?: React.SyntheticEvent<HTMLInputElement>) => void;
|
|
58
|
+
/** Blocks access and changes to the form field */
|
|
59
|
+
disabled?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface IRadioCtx {
|
|
63
|
+
getValueProps: PropGetterFn;
|
|
64
|
+
getTextProps: PropGetterFn;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare const RadioGroup: <T>(props: CProps<IRadioGroupProps & T>) => ReturnEl;
|
|
68
|
+
|
|
69
|
+
export { RadioGroup };
|
|
70
|
+
|
|
71
|
+
declare const Radio: (<T>(props: CProps<IRadioProps & T, IRadioCtx>) => ReturnEl) & {
|
|
72
|
+
Value: <T>(props: IRadioValueProps & T) => ReturnEl;
|
|
73
|
+
Text: typeof Text;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export default Radio;
|
|
@@ -17,14 +17,25 @@ SText {
|
|
|
17
17
|
margin-left: 8px;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
SText[size='m'] {
|
|
21
|
+
font-size: var(--fs-200);
|
|
22
|
+
line-height: var(--lh-200);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
SText[size='l'] {
|
|
26
|
+
font-size: var(--fs-300);
|
|
27
|
+
line-height: var(--lh-300);
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
SValue {
|
|
21
31
|
position: relative;
|
|
22
32
|
flex-shrink: 0;
|
|
23
|
-
margin: 0;
|
|
24
33
|
padding: 0;
|
|
25
34
|
outline: none;
|
|
26
35
|
z-index: 0;
|
|
27
36
|
|
|
37
|
+
margin-top: 2px;
|
|
38
|
+
|
|
28
39
|
&::before {
|
|
29
40
|
content: '';
|
|
30
41
|
position: absolute;
|
|
@@ -52,30 +63,22 @@ SValue {
|
|
|
52
63
|
}
|
|
53
64
|
}
|
|
54
65
|
|
|
55
|
-
SValue[size='
|
|
56
|
-
margin-top: 2px;
|
|
57
|
-
width: 20px;
|
|
58
|
-
height: 20px;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
SValue[size='l'] {
|
|
62
|
-
margin-top: 1px;
|
|
66
|
+
SValue[size='m'] {
|
|
63
67
|
width: 16px;
|
|
64
68
|
height: 16px;
|
|
65
69
|
}
|
|
66
70
|
|
|
67
|
-
SValue[size='
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
height: 12px;
|
|
71
|
+
SValue[size='l'] {
|
|
72
|
+
width: 20px;
|
|
73
|
+
height: 20px;
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
SValue[state='normal']::before {
|
|
74
|
-
border-color: var(--
|
|
77
|
+
border-color: var(--gray-200);
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
SValue[state='invalid']::before {
|
|
78
|
-
border-color: var(--
|
|
81
|
+
border-color: var(--red-400);
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
SControl {
|
|
@@ -84,38 +87,34 @@ SControl {
|
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
SControl:checked ~ SValue::before {
|
|
87
|
-
border-color: var(--
|
|
88
|
-
background-color: var(--
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
SControl:checked ~ SValue[size='xl']::after {
|
|
92
|
-
width: 8px;
|
|
93
|
-
height: 8px;
|
|
90
|
+
border-color: var(--blue-400);
|
|
91
|
+
background-color: var(--blue-400);
|
|
94
92
|
}
|
|
95
93
|
|
|
96
|
-
SControl:checked ~ SValue[size='
|
|
94
|
+
SControl:checked ~ SValue[size='m']::after {
|
|
97
95
|
width: 6px;
|
|
98
96
|
height: 6px;
|
|
99
97
|
}
|
|
100
98
|
|
|
101
|
-
SControl:checked ~ SValue[size='
|
|
102
|
-
width:
|
|
103
|
-
height:
|
|
99
|
+
SControl:checked ~ SValue[size='l']::after {
|
|
100
|
+
width: 8px;
|
|
101
|
+
height: 8px;
|
|
104
102
|
}
|
|
105
103
|
|
|
106
104
|
SValue[state='normal'][keyboardFocused]::before {
|
|
107
|
-
box-shadow: var(--
|
|
108
|
-
border-color: var(--
|
|
105
|
+
box-shadow: var(--keyboard-focus);
|
|
106
|
+
border-color: var(--blue-400);
|
|
109
107
|
}
|
|
110
108
|
|
|
111
109
|
SValue[state='invalid'][keyboardFocused]::before {
|
|
112
|
-
box-shadow:
|
|
110
|
+
box-shadow: var(--keyboard-focus-invalid);
|
|
113
111
|
}
|
|
114
112
|
|
|
115
113
|
SControl:checked ~ SValue[theme]::before {
|
|
116
114
|
border-color: var(--theme);
|
|
117
115
|
background-color: var(--theme);
|
|
118
116
|
}
|
|
117
|
+
|
|
119
118
|
SValue[state='normal'][theme]::before {
|
|
120
119
|
border-color: var(--theme);
|
|
121
120
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { IBoxProps, IFlexProps } from '@semcore/flex-box';
|
|
|
3
3
|
import { IKeyboardFocusProps } from '@semcore/utils/lib/enhances/keyboardFocusEnhance';
|
|
4
4
|
import { Text } from '@semcore/typography';
|
|
5
5
|
|
|
6
|
-
export type RadioSize = 'm' | 'l'
|
|
6
|
+
export type RadioSize = 'm' | 'l';
|
|
7
7
|
export type RadioState = 'normal' | 'invalid';
|
|
8
8
|
export type RadioValue = string | number | boolean;
|
|
9
9
|
|
|
@@ -55,6 +55,8 @@ export interface IRadioValueProps extends IBoxProps, IKeyboardFocusProps {
|
|
|
55
55
|
value?: RadioValue;
|
|
56
56
|
/** Called when the value changes */
|
|
57
57
|
onChange?: (value: boolean, e?: React.SyntheticEvent<HTMLInputElement>) => void;
|
|
58
|
+
/** Blocks access and changes to the form field */
|
|
59
|
+
disabled?: boolean;
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
export interface IRadioCtx {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semcore/radio",
|
|
3
3
|
"description": "SEMRush Radio Component",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.0.1",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/es6/index.js",
|
|
7
7
|
"typings": "lib/types/index.d.ts",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@semcore/utils": "^3.15",
|
|
17
|
-
"@semcore/
|
|
18
|
-
"@semcore/
|
|
17
|
+
"@semcore/flex-box": "^4",
|
|
18
|
+
"@semcore/typography": "^4"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"@semcore/core": "^1.11",
|
|
@@ -28,5 +28,8 @@
|
|
|
28
28
|
"type": "git",
|
|
29
29
|
"url": "https://github.com/semrush/intergalactic.git",
|
|
30
30
|
"directory": "semcore/radio"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@semcore/jest-preset-ui": "1.0.0"
|
|
31
34
|
}
|
|
32
35
|
}
|
package/src/Radio.jsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import createComponent, { Component, CONTEXT_COMPONENT, sstyled, Root } from '@semcore/core';
|
|
3
3
|
import { Box } from '@semcore/flex-box';
|
|
4
|
-
import { Text as TypographyText } from '@semcore/typography';
|
|
5
4
|
import assignProps from '@semcore/utils/lib/assignProps';
|
|
6
5
|
import keyboardFocusEnhance from '@semcore/utils/lib/enhances/keyboardFocusEnhance';
|
|
7
6
|
import resolveColor from '@semcore/utils/lib/color';
|
|
@@ -9,12 +8,6 @@ import getInputProps, { inputProps } from '@semcore/utils/lib/inputProps';
|
|
|
9
8
|
|
|
10
9
|
import style from './style/radio.shadow.css';
|
|
11
10
|
|
|
12
|
-
const SIZE_TEXT_MAP = {
|
|
13
|
-
xl: 300,
|
|
14
|
-
l: 200,
|
|
15
|
-
m: 100,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
11
|
class RadioGroupRoot extends Component {
|
|
19
12
|
static displayName = 'RadioGroup';
|
|
20
13
|
|
|
@@ -81,7 +74,7 @@ class Radio extends Component {
|
|
|
81
74
|
// The default values are here, since you cannot rewrite out of context
|
|
82
75
|
const { size = 'm' } = assignProps(this.props, this.context);
|
|
83
76
|
return {
|
|
84
|
-
size:
|
|
77
|
+
size: size,
|
|
85
78
|
};
|
|
86
79
|
}
|
|
87
80
|
|
|
@@ -114,19 +107,14 @@ class Value extends Component {
|
|
|
114
107
|
render() {
|
|
115
108
|
const SValue = Box;
|
|
116
109
|
const SControl = Box;
|
|
117
|
-
const { forwardRef, styles, includeInputProps,
|
|
110
|
+
const { forwardRef, styles, includeInputProps, theme } = this.asProps;
|
|
118
111
|
|
|
119
112
|
const [controlProps, boxProps] = getInputProps(this.asProps, includeInputProps);
|
|
120
|
-
let color = '';
|
|
121
|
-
|
|
122
|
-
if (theme && state !== 'invalid') {
|
|
123
|
-
color = resolveColor(theme);
|
|
124
|
-
}
|
|
125
113
|
|
|
126
114
|
return sstyled(styles)(
|
|
127
115
|
<>
|
|
128
116
|
<SControl tag="input" type="radio" {...controlProps} />
|
|
129
|
-
<SValue ref={forwardRef} use:theme={
|
|
117
|
+
<SValue ref={forwardRef} use:theme={resolveColor(theme)} {...boxProps} />
|
|
130
118
|
</>,
|
|
131
119
|
);
|
|
132
120
|
}
|
|
@@ -135,7 +123,7 @@ class Value extends Component {
|
|
|
135
123
|
function Text(props) {
|
|
136
124
|
const SText = Root;
|
|
137
125
|
const { styles } = props;
|
|
138
|
-
return sstyled(styles)(<SText render={
|
|
126
|
+
return sstyled(styles)(<SText render={Box} />);
|
|
139
127
|
}
|
|
140
128
|
|
|
141
129
|
export { inputProps, RadioGroup };
|
package/src/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { IBoxProps, IFlexProps } from '@semcore/flex-box';
|
|
|
3
3
|
import { IKeyboardFocusProps } from '@semcore/utils/lib/enhances/keyboardFocusEnhance';
|
|
4
4
|
import { Text } from '@semcore/typography';
|
|
5
5
|
|
|
6
|
-
export type RadioSize = 'm' | 'l'
|
|
6
|
+
export type RadioSize = 'm' | 'l';
|
|
7
7
|
export type RadioState = 'normal' | 'invalid';
|
|
8
8
|
export type RadioValue = string | number | boolean;
|
|
9
9
|
|
|
@@ -55,6 +55,8 @@ export interface IRadioValueProps extends IBoxProps, IKeyboardFocusProps {
|
|
|
55
55
|
value?: RadioValue;
|
|
56
56
|
/** Called when the value changes */
|
|
57
57
|
onChange?: (value: boolean, e?: React.SyntheticEvent<HTMLInputElement>) => void;
|
|
58
|
+
/** Blocks access and changes to the form field */
|
|
59
|
+
disabled?: boolean;
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
export interface IRadioCtx {
|
|
@@ -17,14 +17,25 @@ SText {
|
|
|
17
17
|
margin-left: 8px;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
SText[size='m'] {
|
|
21
|
+
font-size: var(--fs-200);
|
|
22
|
+
line-height: var(--lh-200);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
SText[size='l'] {
|
|
26
|
+
font-size: var(--fs-300);
|
|
27
|
+
line-height: var(--lh-300);
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
SValue {
|
|
21
31
|
position: relative;
|
|
22
32
|
flex-shrink: 0;
|
|
23
|
-
margin: 0;
|
|
24
33
|
padding: 0;
|
|
25
34
|
outline: none;
|
|
26
35
|
z-index: 0;
|
|
27
36
|
|
|
37
|
+
margin-top: 2px;
|
|
38
|
+
|
|
28
39
|
&::before {
|
|
29
40
|
content: '';
|
|
30
41
|
position: absolute;
|
|
@@ -52,30 +63,22 @@ SValue {
|
|
|
52
63
|
}
|
|
53
64
|
}
|
|
54
65
|
|
|
55
|
-
SValue[size='
|
|
56
|
-
margin-top: 2px;
|
|
57
|
-
width: 20px;
|
|
58
|
-
height: 20px;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
SValue[size='l'] {
|
|
62
|
-
margin-top: 1px;
|
|
66
|
+
SValue[size='m'] {
|
|
63
67
|
width: 16px;
|
|
64
68
|
height: 16px;
|
|
65
69
|
}
|
|
66
70
|
|
|
67
|
-
SValue[size='
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
height: 12px;
|
|
71
|
+
SValue[size='l'] {
|
|
72
|
+
width: 20px;
|
|
73
|
+
height: 20px;
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
SValue[state='normal']::before {
|
|
74
|
-
border-color: var(--
|
|
77
|
+
border-color: var(--gray-200);
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
SValue[state='invalid']::before {
|
|
78
|
-
border-color: var(--
|
|
81
|
+
border-color: var(--red-400);
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
SControl {
|
|
@@ -84,38 +87,34 @@ SControl {
|
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
SControl:checked ~ SValue::before {
|
|
87
|
-
border-color: var(--
|
|
88
|
-
background-color: var(--
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
SControl:checked ~ SValue[size='xl']::after {
|
|
92
|
-
width: 8px;
|
|
93
|
-
height: 8px;
|
|
90
|
+
border-color: var(--blue-400);
|
|
91
|
+
background-color: var(--blue-400);
|
|
94
92
|
}
|
|
95
93
|
|
|
96
|
-
SControl:checked ~ SValue[size='
|
|
94
|
+
SControl:checked ~ SValue[size='m']::after {
|
|
97
95
|
width: 6px;
|
|
98
96
|
height: 6px;
|
|
99
97
|
}
|
|
100
98
|
|
|
101
|
-
SControl:checked ~ SValue[size='
|
|
102
|
-
width:
|
|
103
|
-
height:
|
|
99
|
+
SControl:checked ~ SValue[size='l']::after {
|
|
100
|
+
width: 8px;
|
|
101
|
+
height: 8px;
|
|
104
102
|
}
|
|
105
103
|
|
|
106
104
|
SValue[state='normal'][keyboardFocused]::before {
|
|
107
|
-
box-shadow: var(--
|
|
108
|
-
border-color: var(--
|
|
105
|
+
box-shadow: var(--keyboard-focus);
|
|
106
|
+
border-color: var(--blue-400);
|
|
109
107
|
}
|
|
110
108
|
|
|
111
109
|
SValue[state='invalid'][keyboardFocused]::before {
|
|
112
|
-
box-shadow:
|
|
110
|
+
box-shadow: var(--keyboard-focus-invalid);
|
|
113
111
|
}
|
|
114
112
|
|
|
115
113
|
SControl:checked ~ SValue[theme]::before {
|
|
116
114
|
border-color: var(--theme);
|
|
117
115
|
background-color: var(--theme);
|
|
118
116
|
}
|
|
117
|
+
|
|
119
118
|
SValue[state='normal'][theme]::before {
|
|
120
119
|
border-color: var(--theme);
|
|
121
120
|
}
|