|
| 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 | +import { Checkbox, LABEL_PLACEMENT } from "baseui/checkbox-v2"; |
| 9 | +import { PropTypes } from "react-view"; |
| 10 | +import type { TConfig } from "../types"; |
| 11 | +import { changeHandlers } from "./common/common"; |
| 12 | + |
| 13 | +const CheckboxConfig: TConfig = { |
| 14 | + componentName: "Checkbox", |
| 15 | + imports: { |
| 16 | + "baseui/checkbox-v2": { |
| 17 | + named: ["Checkbox"], |
| 18 | + }, |
| 19 | + }, |
| 20 | + scope: { |
| 21 | + Checkbox, |
| 22 | + LABEL_PLACEMENT, |
| 23 | + }, |
| 24 | + theme: [ |
| 25 | + "contentStateDisabled", |
| 26 | + "tagRedContentSecondary", |
| 27 | + "borderSelected", |
| 28 | + "contentTertiary", |
| 29 | + "contentPrimary", |
| 30 | + "hoverNegativeAlpha", |
| 31 | + "hoverOverlayAlpha", |
| 32 | + "pressedNegativeAlpha", |
| 33 | + "pressedOverlayAlpha", |
| 34 | + "contentInversePrimary", |
| 35 | + ], |
| 36 | + props: { |
| 37 | + checked: { |
| 38 | + value: false, |
| 39 | + type: PropTypes.Boolean, |
| 40 | + description: "Renders component in checked state.", |
| 41 | + stateful: true, |
| 42 | + }, |
| 43 | + children: { |
| 44 | + value: `Sign up for the newsletter`, |
| 45 | + type: PropTypes.ReactNode, |
| 46 | + description: `The React Nodes displayed next to the checkbox.`, |
| 47 | + }, |
| 48 | + disabled: { |
| 49 | + value: false, |
| 50 | + type: PropTypes.Boolean, |
| 51 | + description: "Renders component in disabled state.", |
| 52 | + }, |
| 53 | + onChange: { |
| 54 | + value: "e => setChecked(e.target.checked)", |
| 55 | + type: PropTypes.Function, |
| 56 | + description: "Called when checkbox value is changed.", |
| 57 | + propHook: { |
| 58 | + what: "e.target.checked", |
| 59 | + into: "checked", |
| 60 | + }, |
| 61 | + }, |
| 62 | + error: { |
| 63 | + value: false, |
| 64 | + type: PropTypes.Boolean, |
| 65 | + description: "Renders component in error state.", |
| 66 | + }, |
| 67 | + isIndeterminate: { |
| 68 | + value: false, |
| 69 | + type: PropTypes.Boolean, |
| 70 | + description: |
| 71 | + "Indicates indeterminate state for the checkbox. Checked property is ignored.", |
| 72 | + }, |
| 73 | + labelPlacement: { |
| 74 | + value: "LABEL_PLACEMENT.right", |
| 75 | + options: LABEL_PLACEMENT, |
| 76 | + type: PropTypes.Enum, |
| 77 | + enumName: "LABEL_PLACEMENT", |
| 78 | + description: |
| 79 | + "Determines how to position the label relative to the checkbox.", |
| 80 | + imports: { |
| 81 | + "baseui/checkbox-v2": { |
| 82 | + named: ["LABEL_PLACEMENT"], |
| 83 | + }, |
| 84 | + }, |
| 85 | + }, |
| 86 | + required: { |
| 87 | + value: false, |
| 88 | + type: PropTypes.Boolean, |
| 89 | + description: "Renders component in required state.", |
| 90 | + hidden: true, |
| 91 | + }, |
| 92 | + inputRef: { |
| 93 | + value: undefined, |
| 94 | + type: PropTypes.Ref, |
| 95 | + description: "A ref to access an input element.", |
| 96 | + hidden: true, |
| 97 | + }, |
| 98 | + autoFocus: { |
| 99 | + value: false, |
| 100 | + type: PropTypes.Boolean, |
| 101 | + description: "If true the component will be focused on the first mount.", |
| 102 | + hidden: true, |
| 103 | + }, |
| 104 | + containsInteractiveElement: { |
| 105 | + value: false, |
| 106 | + type: PropTypes.Boolean, |
| 107 | + description: |
| 108 | + "Indicates the checkbox label contains an interactive element, and the default label behavior should be prevented for child elements.", |
| 109 | + hidden: true, |
| 110 | + }, |
| 111 | + name: { |
| 112 | + value: undefined, |
| 113 | + type: PropTypes.String, |
| 114 | + description: "Name attribute.", |
| 115 | + hidden: true, |
| 116 | + }, |
| 117 | + title: { |
| 118 | + value: undefined, |
| 119 | + type: PropTypes.String, |
| 120 | + description: "Title attribute.", |
| 121 | + hidden: true, |
| 122 | + }, |
| 123 | + "aria-label": { |
| 124 | + value: undefined, |
| 125 | + type: PropTypes.String, |
| 126 | + description: "Aria-label attribute", |
| 127 | + hidden: true, |
| 128 | + }, |
| 129 | + ...pick(changeHandlers, [ |
| 130 | + "onBlur", |
| 131 | + "onFocus", |
| 132 | + "onMouseDown", |
| 133 | + "onMouseEnter", |
| 134 | + "onMouseLeave", |
| 135 | + ]), |
| 136 | + overrides: { |
| 137 | + value: undefined, |
| 138 | + type: PropTypes.Custom, |
| 139 | + description: "Lets you customize all aspects of the component.", |
| 140 | + custom: { |
| 141 | + names: ["Root", "CheckmarkContainer", "Checkmark", "Label", "Input"], |
| 142 | + sharedProps: { |
| 143 | + $isFocused: { |
| 144 | + type: PropTypes.Boolean, |
| 145 | + description: "True when the component is focused.", |
| 146 | + }, |
| 147 | + $isHovered: { |
| 148 | + type: PropTypes.Boolean, |
| 149 | + description: "True when the component is hovered.", |
| 150 | + }, |
| 151 | + $isActive: { |
| 152 | + type: PropTypes.Boolean, |
| 153 | + description: "True when the component is active.", |
| 154 | + }, |
| 155 | + $error: "error", |
| 156 | + $checked: "checked", |
| 157 | + $isIndeterminate: "isIndeterminate", |
| 158 | + $required: "required", |
| 159 | + $disabled: "disabled", |
| 160 | + $labelPlacement: "labelPlacement", |
| 161 | + }, |
| 162 | + }, |
| 163 | + }, |
| 164 | + }, |
| 165 | +}; |
| 166 | + |
| 167 | +export default CheckboxConfig; |
0 commit comments