|
| 1 | +/* |
| 2 | +Copyright (c) Uber Technologies, Inc. |
| 3 | +
|
| 4 | +This source code is licensed under the MIT license found in the |
| 5 | +LICENSE file in the root directory of this source tree. |
| 6 | +*/ |
| 7 | +import pick from "just-pick"; |
| 8 | + |
| 9 | +import { Radio, RadioGroup, ALIGN, LABEL_PLACEMENT } from "baseui/radio-v2"; |
| 10 | +import { PropTypes } from "react-view"; |
| 11 | +import type { TConfig } from "../types"; |
| 12 | + |
| 13 | +import { changeHandlers } from "./common/common"; |
| 14 | + |
| 15 | +const RadioGroupConfig: TConfig = { |
| 16 | + componentName: "RadioGroup", |
| 17 | + imports: { |
| 18 | + "baseui/radio-v2": { named: ["RadioGroup"] }, |
| 19 | + }, |
| 20 | + scope: { |
| 21 | + Radio, |
| 22 | + RadioGroup, |
| 23 | + ALIGN, |
| 24 | + LABEL_PLACEMENT, |
| 25 | + }, |
| 26 | + theme: [ |
| 27 | + "tickFill", |
| 28 | + "tickFillHover", |
| 29 | + "tickFillActive", |
| 30 | + "tickFillSelected", |
| 31 | + "tickFillSelectedHover", |
| 32 | + "tickFillSelectedHoverActive", |
| 33 | + "tickFillError", |
| 34 | + "tickFillErrorHover", |
| 35 | + "tickFillErrorHoverActive", |
| 36 | + "tickFillErrorSelected", |
| 37 | + "tickFillErrorSelectedHover", |
| 38 | + "tickFillErrorSelectedHoverActive", |
| 39 | + "tickFillDisabled", |
| 40 | + "tickBorder", |
| 41 | + "tickBorderError", |
| 42 | + "tickMarkFill", |
| 43 | + "tickMarkFillError", |
| 44 | + "tickMarkFillDisabled", |
| 45 | + ], |
| 46 | + props: { |
| 47 | + value: { |
| 48 | + value: "2", |
| 49 | + type: PropTypes.String, |
| 50 | + description: "Passed to the input element value attribute", |
| 51 | + stateful: true, |
| 52 | + }, |
| 53 | + onChange: { |
| 54 | + value: "e => setValue(e.currentTarget.value)", |
| 55 | + type: PropTypes.Function, |
| 56 | + description: "Handler for change events on trigger element.", |
| 57 | + propHook: { |
| 58 | + what: "e.target.value", |
| 59 | + into: "value", |
| 60 | + }, |
| 61 | + }, |
| 62 | + children: { |
| 63 | + value: `<Radio value="1">One</Radio> |
| 64 | +<Radio |
| 65 | + value="2" |
| 66 | + description="This is a radio-v2 description" |
| 67 | +> |
| 68 | + Two |
| 69 | +</Radio> |
| 70 | +<Radio value="3"> |
| 71 | + Three |
| 72 | +</Radio>`, |
| 73 | + type: PropTypes.ReactNode, |
| 74 | + description: "Radios within the RadioGroup", |
| 75 | + imports: { |
| 76 | + "baseui/radio-v2": { named: ["Radio"] }, |
| 77 | + }, |
| 78 | + }, |
| 79 | + name: { |
| 80 | + value: "number", |
| 81 | + type: PropTypes.String, |
| 82 | + description: |
| 83 | + "String value for the name of RadioGroup, it is used to group buttons. If missed default is random ID string.", |
| 84 | + hidden: false, |
| 85 | + }, |
| 86 | + align: { |
| 87 | + value: "ALIGN.vertical", |
| 88 | + type: PropTypes.Enum, |
| 89 | + options: ALIGN, |
| 90 | + description: "How to position radio-v2 buttons in the group.", |
| 91 | + imports: { |
| 92 | + "baseui/radio-v2": { |
| 93 | + named: ["ALIGN"], |
| 94 | + }, |
| 95 | + }, |
| 96 | + }, |
| 97 | + labelPlacement: { |
| 98 | + value: "LABEL_PLACEMENT.right", |
| 99 | + type: PropTypes.Enum, |
| 100 | + options: LABEL_PLACEMENT, |
| 101 | + enumName: "LABEL_PLACEMENT", |
| 102 | + description: |
| 103 | + "How to position radio-v2 label relative to the radio itself.", |
| 104 | + imports: { |
| 105 | + "baseui/radio-v2": { |
| 106 | + named: ["LABEL_PLACEMENT"], |
| 107 | + }, |
| 108 | + }, |
| 109 | + }, |
| 110 | + disabled: { |
| 111 | + value: false, |
| 112 | + type: PropTypes.Boolean, |
| 113 | + description: |
| 114 | + "Disabled all radio-v2 group from being changed. To disable some of radios provide disabled flag in each of them.", |
| 115 | + }, |
| 116 | + error: { |
| 117 | + value: false, |
| 118 | + type: PropTypes.Boolean, |
| 119 | + description: "Sets radio-v2 group into error state.", |
| 120 | + }, |
| 121 | + required: { |
| 122 | + value: false, |
| 123 | + type: PropTypes.Boolean, |
| 124 | + description: "Set if the control is required to be checked.", |
| 125 | + hidden: true, |
| 126 | + }, |
| 127 | + autoFocus: { |
| 128 | + value: false, |
| 129 | + type: PropTypes.Boolean, |
| 130 | + description: "Set to be focused (active) on selectedchecked radio-v2.", |
| 131 | + hidden: true, |
| 132 | + }, |
| 133 | + containsInteractiveElement: { |
| 134 | + value: false, |
| 135 | + type: PropTypes.Boolean, |
| 136 | + description: |
| 137 | + "Indicates the radio-v2 contains an interactive element, and the default label behavior should be prevented for child elements.", |
| 138 | + hidden: true, |
| 139 | + }, |
| 140 | + "aria-label": { |
| 141 | + value: undefined, |
| 142 | + type: PropTypes.String, |
| 143 | + description: `Sets aria-label attribute.`, |
| 144 | + hidden: true, |
| 145 | + }, |
| 146 | + "aria-labelledby": { |
| 147 | + value: undefined, |
| 148 | + type: PropTypes.String, |
| 149 | + description: `Sets aria-labelledby attribute.`, |
| 150 | + hidden: true, |
| 151 | + }, |
| 152 | + ...pick(changeHandlers, [ |
| 153 | + "onBlur", |
| 154 | + "onFocus", |
| 155 | + "onMouseLeave", |
| 156 | + "onMouseEnter", |
| 157 | + ]), |
| 158 | + overrides: { |
| 159 | + value: undefined, |
| 160 | + type: PropTypes.Custom, |
| 161 | + description: "Lets you customize all aspects of the component.", |
| 162 | + custom: { |
| 163 | + names: ["Root"], |
| 164 | + sharedProps: { |
| 165 | + $isFocused: { |
| 166 | + type: PropTypes.Boolean, |
| 167 | + description: "True when the component is focused.", |
| 168 | + }, |
| 169 | + $isHovered: { |
| 170 | + type: PropTypes.Boolean, |
| 171 | + description: "True when the component is hovered.", |
| 172 | + }, |
| 173 | + $isActive: { |
| 174 | + type: PropTypes.Boolean, |
| 175 | + description: "True when the component is active.", |
| 176 | + }, |
| 177 | + $error: "error", |
| 178 | + $checked: { |
| 179 | + type: PropTypes.Boolean, |
| 180 | + description: "True when the component is active.", |
| 181 | + }, |
| 182 | + $required: "required", |
| 183 | + $disabled: "disabled", |
| 184 | + }, |
| 185 | + }, |
| 186 | + }, |
| 187 | + }, |
| 188 | +}; |
| 189 | + |
| 190 | +export default RadioGroupConfig; |
0 commit comments