|
1 | 1 | import React from 'react' |
| 2 | +import PropTypes from 'prop-types' |
2 | 3 | import InnerSwitch from './internal/InnerSwitch' |
3 | 4 | import createComponent from './internal/createComponent' |
4 | 5 |
|
5 | | -const Checkbox = createComponent( |
6 | | - ({ css, mixin, th, classNames, PropTypes }) => ({ |
7 | | - name: 'checkbox', |
8 | | - render: ({ Component, className, size, ...props }) => ( |
9 | | - <Component |
10 | | - className={classNames(className, { |
11 | | - 'sui-checkbox-disabled': props.disabled, |
12 | | - [`sui-checkbox-${size}`]: size, |
13 | | - })} |
14 | | - > |
15 | | - <InnerSwitch inputType="checkbox" {...props}> |
16 | | - {({ checked, focused, disabled }) => ( |
17 | | - <div |
18 | | - className={classNames('sui-checkbox-content', { |
19 | | - checked, |
20 | | - focused, |
21 | | - disabled, |
22 | | - })} |
23 | | - > |
24 | | - <svg viewBox="0 0 10 8"> |
25 | | - <path |
26 | | - d="M3.7 7.3L.3 4l1-.8 2.4 2.3 5-4.8 1 1" |
27 | | - fill="#fff" |
28 | | - fillRule="evenodd" |
29 | | - /> |
30 | | - </svg> |
31 | | - </div> |
32 | | - )} |
33 | | - </InnerSwitch> |
34 | | - </Component> |
35 | | - ), |
36 | | - style: css` |
37 | | - display: inline-block; |
38 | | - position: relative; |
39 | | - width: 1.5rem; |
40 | | - height: 1.5rem; |
41 | | - z-index: ${th('zIndexControl')}; |
| 6 | +const Checkbox = createComponent(({ css, mixin, th, classNames }) => ({ |
| 7 | + name: 'checkbox', |
| 8 | + render: ({ Component, className, size, ...props }) => ( |
| 9 | + <Component |
| 10 | + className={classNames(className, { |
| 11 | + 'sui-checkbox-disabled': props.disabled, |
| 12 | + [`sui-checkbox-${size}`]: size, |
| 13 | + })} |
| 14 | + > |
| 15 | + <InnerSwitch inputType="checkbox" {...props}> |
| 16 | + {({ checked, focused, disabled }) => ( |
| 17 | + <div |
| 18 | + className={classNames('sui-checkbox-content', { |
| 19 | + checked, |
| 20 | + focused, |
| 21 | + disabled, |
| 22 | + })} |
| 23 | + > |
| 24 | + <svg viewBox="0 0 10 8"> |
| 25 | + <path |
| 26 | + d="M3.7 7.3L.3 4l1-.8 2.4 2.3 5-4.8 1 1" |
| 27 | + fill="#fff" |
| 28 | + fillRule="evenodd" |
| 29 | + /> |
| 30 | + </svg> |
| 31 | + </div> |
| 32 | + )} |
| 33 | + </InnerSwitch> |
| 34 | + </Component> |
| 35 | + ), |
| 36 | + style: css` |
| 37 | + display: inline-block; |
| 38 | + position: relative; |
| 39 | + width: 1.5rem; |
| 40 | + height: 1.5rem; |
| 41 | + z-index: ${th('zIndexControl')}; |
42 | 42 |
|
43 | | - .sui-checkbox-content { |
44 | | - display: flex; |
45 | | - align-items: center; |
46 | | - justify-content: center; |
47 | | - width: 1rem; |
48 | | - height: 1rem; |
49 | | - background-color: ${th('inputBgColor')}; |
50 | | - border-radius: ${th('borderRadius')}; |
51 | | - border-style: solid; |
52 | | - border-width: ${th('inputBorderWidth')}; |
53 | | - border-color: ${th('inputBorderColor')}; |
54 | | - transition: ${th('transitionBase')}; |
55 | | -
|
56 | | - &.checked { |
57 | | - background-color: ${th('primary')}; |
58 | | - border-color: transparent; |
| 43 | + .sui-checkbox-content { |
| 44 | + display: flex; |
| 45 | + align-items: center; |
| 46 | + justify-content: center; |
| 47 | + width: 1rem; |
| 48 | + height: 1rem; |
| 49 | + background-color: ${th('inputBgColor')}; |
| 50 | + border-radius: ${th('borderRadius')}; |
| 51 | + border-style: solid; |
| 52 | + border-width: ${th('inputBorderWidth')}; |
| 53 | + border-color: ${th('inputBorderColor')}; |
| 54 | + transition: ${th('transitionBase')}; |
59 | 55 |
|
60 | | - svg { |
61 | | - transform: scale(1); |
62 | | - } |
63 | | - } |
| 56 | + &.checked { |
| 57 | + background-color: ${th('primary')}; |
| 58 | + border-color: transparent; |
64 | 59 |
|
65 | | - &.focused { |
66 | | - ${mixin('controlFocus')}; |
| 60 | + svg { |
| 61 | + transform: scale(1); |
67 | 62 | } |
| 63 | + } |
68 | 64 |
|
69 | | - &.disabled { |
70 | | - background-color: ${th('inputDisabledBgColor')}; |
71 | | - } |
| 65 | + &.focused { |
| 66 | + ${mixin('controlFocus')}; |
72 | 67 | } |
73 | 68 |
|
74 | | - svg { |
75 | | - width: 0.75rem; |
76 | | - pointer-events: none; |
77 | | - transform: scale(0); |
78 | | - transition: ${th('transitionBase')}; |
| 69 | + &.disabled { |
| 70 | + background-color: ${th('inputDisabledBgColor')}; |
79 | 71 | } |
| 72 | + } |
80 | 73 |
|
81 | | - &.sui-checkbox-sm { |
82 | | - .sui-checkbox-content { |
83 | | - border-radius: ${th('borderRadiusSm')}; |
84 | | - width: 0.875rem; |
85 | | - height: 0.875rem; |
86 | | - } |
| 74 | + svg { |
| 75 | + width: 0.75rem; |
| 76 | + pointer-events: none; |
| 77 | + transform: scale(0); |
| 78 | + transition: ${th('transitionBase')}; |
| 79 | + } |
87 | 80 |
|
88 | | - svg { |
89 | | - width: 0.65rem; |
90 | | - } |
| 81 | + &.sui-checkbox-sm { |
| 82 | + .sui-checkbox-content { |
| 83 | + border-radius: ${th('borderRadiusSm')}; |
| 84 | + width: 0.875rem; |
| 85 | + height: 0.875rem; |
91 | 86 | } |
92 | 87 |
|
93 | | - &.sui-checkbox-lg { |
94 | | - .sui-checkbox-content { |
95 | | - border-radius: ${th('borderRadiusLg')}; |
96 | | - width: 1.25rem; |
97 | | - height: 1.25rem; |
98 | | - } |
| 88 | + svg { |
| 89 | + width: 0.65rem; |
| 90 | + } |
| 91 | + } |
99 | 92 |
|
100 | | - svg { |
101 | | - width: 0.9375rem; |
102 | | - } |
| 93 | + &.sui-checkbox-lg { |
| 94 | + .sui-checkbox-content { |
| 95 | + border-radius: ${th('borderRadiusLg')}; |
| 96 | + width: 1.25rem; |
| 97 | + height: 1.25rem; |
| 98 | + } |
| 99 | +
|
| 100 | + svg { |
| 101 | + width: 0.9375rem; |
103 | 102 | } |
104 | | - `, |
105 | | - propTypes: { |
106 | | - checked: PropTypes.bool, |
107 | | - disabled: PropTypes.bool, |
108 | | - onChange: PropTypes.func, |
109 | | - size: PropTypes.oneOf(['sm', 'lg']), |
110 | | - value: PropTypes.string, |
111 | | - }, |
112 | | - }), |
113 | | -) |
| 103 | + } |
| 104 | + `, |
| 105 | + propTypes: { |
| 106 | + checked: PropTypes.bool, |
| 107 | + disabled: PropTypes.bool, |
| 108 | + onChange: PropTypes.func, |
| 109 | + size: PropTypes.oneOf(['sm', 'lg']), |
| 110 | + value: PropTypes.string, |
| 111 | + }, |
| 112 | +})) |
114 | 113 |
|
115 | 114 | export default Checkbox |
0 commit comments