|
| 1 | +import { |
| 2 | + Stack, |
| 3 | + styled, |
| 4 | +} from '@tamagui/web' |
| 5 | + |
| 6 | + |
| 7 | +export const Focusable = styled(Stack, { |
| 8 | + |
| 9 | + |
| 10 | + name: 'Focusable', |
| 11 | + |
| 12 | + acceptsClassName: true, |
| 13 | + userSelect: 'none', |
| 14 | + cursor: 'pointer', |
| 15 | + |
| 16 | + borderWidth: 1, |
| 17 | + borderStyle: 'solid', |
| 18 | + borderColor: 'transparent', |
| 19 | + alignItems: 'center', |
| 20 | + flexDirection: 'row', |
| 21 | + pressStyle: { |
| 22 | + transform: `translateY(1px);` |
| 23 | + }, |
| 24 | + focusStyle: { |
| 25 | + shadowColor: '0 0 0 2px var(--rcx-button-primary-focus-shadow-color, var(--rcx-color-shadow-highlight, var(--rcx-color-blue-200, #D1EBFE)))', |
| 26 | + }, |
| 27 | + |
| 28 | + variants: { |
| 29 | + |
| 30 | + primary: (value, { props }) => { |
| 31 | + switch (true) { |
| 32 | + case value && !props.disabled: { |
| 33 | + return { |
| 34 | + |
| 35 | + backgroundColor: "$backgroundPrimaryDefault", |
| 36 | + borderColor: "$primary_default", |
| 37 | + color: "$fontOnPrimary", |
| 38 | + |
| 39 | + hoverStyle: { |
| 40 | + backgroundColor: "$backgroundPrimaryHover", |
| 41 | + borderColor: "$primary_hover", |
| 42 | + }, |
| 43 | + |
| 44 | + pressStyle: { |
| 45 | + backgroundColor: "$backgroundPrimaryPress", |
| 46 | + borderColor: "$primary_press", |
| 47 | + }, |
| 48 | + focusStyle: { |
| 49 | + backgroundColor: "$backgroundPrimaryFocus", |
| 50 | + borderColor: "$primary_focus", |
| 51 | + }, |
| 52 | + } |
| 53 | + } |
| 54 | + case value && props.disabled: { |
| 55 | + return { |
| 56 | + backgroundColor: "$backgroundPrimaryDisabled", |
| 57 | + borderColor: "$primary_disabled", |
| 58 | + color: "$fontOnPrimaryDisabled", |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + }, |
| 64 | + |
| 65 | + secondary: (value, { props }) => { |
| 66 | + switch (true) { |
| 67 | + case value && !props.disabled: { |
| 68 | + return { |
| 69 | + |
| 70 | + backgroundColor: "$backgroundSecondaryDefault", |
| 71 | + borderColor: "$secondary_default", |
| 72 | + color: "$fontOnSecondary", |
| 73 | + |
| 74 | + hoverStyle: { |
| 75 | + backgroundColor: "$backgroundSecondaryHover", |
| 76 | + borderColor: "$secondary_hover", |
| 77 | + }, |
| 78 | + |
| 79 | + pressStyle: { |
| 80 | + backgroundColor: "$backgroundSecondaryPress", |
| 81 | + borderColor: "$secondary_press", |
| 82 | + }, |
| 83 | + focusStyle: { |
| 84 | + backgroundColor: "$backgroundSecondaryFocus", |
| 85 | + borderColor: "$secondary_focus", |
| 86 | + }, |
| 87 | + } |
| 88 | + } |
| 89 | + case value && props.disabled: { |
| 90 | + return { |
| 91 | + backgroundColor: "$backgroundSecondaryDisabled", |
| 92 | + borderColor: "$secondary_disabled", |
| 93 | + color: "$fontOnSecondaryDisabled", |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + }, |
| 98 | + danger: (value, { props }) => { |
| 99 | + switch (true) { |
| 100 | + case value && !props.secondary: { |
| 101 | + return { |
| 102 | + |
| 103 | + backgroundColor: "$backgroundDangerDefault", |
| 104 | + borderColor: "$danger_default", |
| 105 | + color: "$fontOnDanger", |
| 106 | + |
| 107 | + hoverStyle: { |
| 108 | + backgroundColor: "$backgroundDangerHover", |
| 109 | + borderColor: "$danger_hover", |
| 110 | + }, |
| 111 | + |
| 112 | + pressStyle: { |
| 113 | + backgroundColor: "$backgroundDangerPress", |
| 114 | + borderColor: "$danger_press", |
| 115 | + }, |
| 116 | + focusStyle: { |
| 117 | + backgroundColor: "$backgroundDangerFocus", |
| 118 | + borderColor: "$danger_focus", |
| 119 | + }, |
| 120 | + } |
| 121 | + } |
| 122 | + case value && props.secondary: { |
| 123 | + return { |
| 124 | + |
| 125 | + backgroundColor: "$backgroundSecondaryDangerDefault", |
| 126 | + borderColor: "$secondary_danger_default", |
| 127 | + color: "$on_secondary_danger", |
| 128 | + |
| 129 | + hoverStyle: { |
| 130 | + backgroundColor: "$backgroundSecondaryDangerHover", |
| 131 | + borderColor: "$secondary_danger_hover", |
| 132 | + }, |
| 133 | + |
| 134 | + pressStyle: { |
| 135 | + backgroundColor: "$backgroundSecondaryDangerPress", |
| 136 | + borderColor: "$secondary_danger_press", |
| 137 | + }, |
| 138 | + focusStyle: { |
| 139 | + backgroundColor: "$backgroundSecondaryDangerFocus", |
| 140 | + borderColor: "$secondary_danger_focus", |
| 141 | + }, |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | + }, |
| 146 | + warning: (value, { props }) => { |
| 147 | + switch (true) { |
| 148 | + case value && !props.secondary: { |
| 149 | + return { |
| 150 | + |
| 151 | + backgroundColor: "$backgroundWarningDefault", |
| 152 | + borderColor: "$warning_default", |
| 153 | + color: "$fontOnWarning", |
| 154 | + |
| 155 | + hoverStyle: { |
| 156 | + backgroundColor: "$backgroundWarningHover", |
| 157 | + borderColor: "$warning_hover", |
| 158 | + }, |
| 159 | + |
| 160 | + pressStyle: { |
| 161 | + backgroundColor: "$backgroundWarningPress", |
| 162 | + borderColor: "$warning_press", |
| 163 | + }, |
| 164 | + focusStyle: { |
| 165 | + backgroundColor: "$backgroundWarningFocus", |
| 166 | + borderColor: "$warning_focus", |
| 167 | + }, |
| 168 | + } |
| 169 | + } |
| 170 | + case value && props.secondary: { |
| 171 | + return { |
| 172 | + |
| 173 | + backgroundColor: "$backgroundSecondaryWarningDefault", |
| 174 | + borderColor: "$secondary_warning_default", |
| 175 | + color: "$on_secondary_warning", |
| 176 | + |
| 177 | + hoverStyle: { |
| 178 | + backgroundColor: "$backgroundSecondaryWarningHover", |
| 179 | + borderColor: "$secondary_warning_hover", |
| 180 | + }, |
| 181 | + |
| 182 | + pressStyle: { |
| 183 | + backgroundColor: "$backgroundSecondaryWarningPress", |
| 184 | + borderColor: "$secondary_warning_press", |
| 185 | + }, |
| 186 | + focusStyle: { |
| 187 | + backgroundColor: "$backgroundSecondaryWarningFocus", |
| 188 | + borderColor: "$secondary_warning_focus", |
| 189 | + }, |
| 190 | + } |
| 191 | + } |
| 192 | + } |
| 193 | + }, |
| 194 | + success: (value, { props }) => { |
| 195 | + switch (true) { |
| 196 | + case value && !props.secondary: { |
| 197 | + return { |
| 198 | + |
| 199 | + backgroundColor: "$backgroundSuccessDefault", |
| 200 | + borderColor: "$success_default", |
| 201 | + color: "$fontOnSuccess", |
| 202 | + |
| 203 | + hoverStyle: { |
| 204 | + backgroundColor: "$backgroundSuccessHover", |
| 205 | + borderColor: "$success_hover", |
| 206 | + }, |
| 207 | + |
| 208 | + pressStyle: { |
| 209 | + backgroundColor: "$backgroundSuccessPress", |
| 210 | + borderColor: "$success_press", |
| 211 | + }, |
| 212 | + focusStyle: { |
| 213 | + backgroundColor: "$backgroundSuccessFocus", |
| 214 | + borderColor: "$success_focus", |
| 215 | + }, |
| 216 | + } |
| 217 | + } |
| 218 | + case value && props.secondary: { |
| 219 | + return { |
| 220 | + |
| 221 | + backgroundColor: "$backgroundSecondarySuccessDefault", |
| 222 | + borderColor: "$secondary_success_default", |
| 223 | + color: "$on_secondary_success", |
| 224 | + |
| 225 | + hoverStyle: { |
| 226 | + backgroundColor: "$backgroundSecondarySuccessHover", |
| 227 | + borderColor: "$secondary_success_hover", |
| 228 | + }, |
| 229 | + |
| 230 | + pressStyle: { |
| 231 | + backgroundColor: "$backgroundSecondarySuccessPress", |
| 232 | + borderColor: "$secondary_success_press", |
| 233 | + }, |
| 234 | + focusStyle: { |
| 235 | + backgroundColor: "$backgroundSecondarySuccessFocus", |
| 236 | + borderColor: "$secondary_success_focus", |
| 237 | + }, |
| 238 | + } |
| 239 | + } |
| 240 | + } |
| 241 | + }, |
| 242 | + |
| 243 | + disabled: { |
| 244 | + true: { |
| 245 | + opacity: 0.5, |
| 246 | + cursor: 'not-allowed', |
| 247 | + pointerEvents: 'none', |
| 248 | + disabled: true, |
| 249 | + focusable: undefined, |
| 250 | + } |
| 251 | + } |
| 252 | + } as const, |
| 253 | +}) |
0 commit comments