| 1 | import styled from "styled-components"; |
| 2 | import { getFontSize } from "../util"; |
| 3 | |
| 4 | export const VSC_INPUT_BACKGROUND_VAR = "--vscode-input-background"; |
| 5 | export const VSC_BACKGROUND_VAR = "--vscode-sideBar-background"; |
| 6 | export const VSC_FOREGROUND_VAR = "--vscode-editor-foreground"; |
| 7 | export const VSC_BUTTON_BACKGROUND_VAR = "--vscode-button-background"; |
| 8 | export const VSC_BUTTON_FOREGROUND_VAR = "--vscode-button-foreground"; |
| 9 | export const VSC_EDITOR_BACKGROUND_VAR = "--vscode-editor-background"; |
| 10 | export const VSC_LIST_SELECTION_BACKGROUND_VAR = |
| 11 | "--vscode-list-activeSelectionBackground"; |
| 12 | export const VSC_FOCUS_BORDER_VAR = "--vscode-focusBorder"; |
| 13 | export const VSC_LIST_ACTIVE_FOREGROUND_VAR = |
| 14 | "--vscode-quickInputList-focusForeground"; |
| 15 | export const VSC_QUICK_INPUT_BACKGROUND_VAR = "--vscode-quickInput-background"; |
| 16 | export const VSC_INPUT_BORDER_VAR = "--vscode-input-border"; |
| 17 | export const VSC_BADGE_BACKGROUND_VAR = "--vscode-badge-background"; |
| 18 | export const VSC_BADGE_FOREGROUND_VAR = "--vscode-badge-foreground"; |
| 19 | export const VSC_COMMAND_CENTER_ACTIVE_BORDER_VAR = |
| 20 | "--vscode-commandCenter-activeBorder"; |
| 21 | export const VSC_COMMAND_CENTER_INACTIVE_BORDER_VAR = |
| 22 | "--vscode-commandCenter-inactiveBorder"; |
| 23 | export const VSC_FIND_MATCH_SELECTED_VAR = |
| 24 | "--vscode-editor-findMatchHighlightBackground"; |
| 25 | |
| 26 | export const VSC_THEME_COLOR_VARS = [ |
| 27 | VSC_INPUT_BACKGROUND_VAR, |
| 28 | VSC_BACKGROUND_VAR, |
| 29 | VSC_FOREGROUND_VAR, |
| 30 | VSC_BUTTON_BACKGROUND_VAR, |
| 31 | VSC_BUTTON_FOREGROUND_VAR, |
| 32 | VSC_EDITOR_BACKGROUND_VAR, |
| 33 | VSC_LIST_SELECTION_BACKGROUND_VAR, |
| 34 | VSC_FOCUS_BORDER_VAR, |
| 35 | VSC_LIST_ACTIVE_FOREGROUND_VAR, |
| 36 | VSC_QUICK_INPUT_BACKGROUND_VAR, |
| 37 | VSC_INPUT_BORDER_VAR, |
| 38 | VSC_BADGE_BACKGROUND_VAR, |
| 39 | VSC_BADGE_FOREGROUND_VAR, |
| 40 | VSC_COMMAND_CENTER_ACTIVE_BORDER_VAR, |
| 41 | VSC_COMMAND_CENTER_INACTIVE_BORDER_VAR, |
| 42 | VSC_FIND_MATCH_SELECTED_VAR, |
| 43 | ]; |
| 44 | |
| 45 | export const defaultBorderRadius = "5px"; |
| 46 | export const lightGray = "#999998"; |
| 47 | export const greenButtonColor = "#189e72"; |
| 48 | |
| 49 | export const vscInputBackground = `var(${VSC_INPUT_BACKGROUND_VAR}, rgb(45 45 45))`; |
| 50 | export const vscQuickInputBackground = `var(${VSC_QUICK_INPUT_BACKGROUND_VAR}, ${VSC_INPUT_BACKGROUND_VAR}, rgb(45 45 45))`; |
| 51 | export const vscBackground = `var(${VSC_BACKGROUND_VAR}, rgb(30 30 30))`; |
| 52 | export const vscForeground = `var(${VSC_FOREGROUND_VAR}, #fff)`; |
| 53 | export const vscButtonBackground = `var(${VSC_BUTTON_BACKGROUND_VAR}, #1bbe84)`; |
| 54 | export const vscButtonForeground = `var(${VSC_BUTTON_FOREGROUND_VAR}, #ffffff)`; |
| 55 | export const vscEditorBackground = `var(${VSC_EDITOR_BACKGROUND_VAR}, ${VSC_BACKGROUND_VAR}, rgb(30 30 30))`; |
| 56 | export const vscListActiveBackground = `var(${VSC_LIST_SELECTION_BACKGROUND_VAR}, #1bbe84)`; |
| 57 | export const vscFocusBorder = `var(${VSC_FOCUS_BORDER_VAR}, #1bbe84)`; |
| 58 | export const vscListActiveForeground = `var(${VSC_LIST_ACTIVE_FOREGROUND_VAR}, ${VSC_FOREGROUND_VAR})`; |
| 59 | export const vscInputBorder = `var(${VSC_INPUT_BORDER_VAR}, ${lightGray})`; |
| 60 | export const vscInputBorderFocus = `var(${VSC_FOCUS_BORDER_VAR}, ${lightGray})`; |
| 61 | export const vscBadgeBackground = `var(${VSC_BADGE_BACKGROUND_VAR}, #1bbe84)`; |
| 62 | export const vscBadgeForeground = `var(${VSC_BADGE_FOREGROUND_VAR}, #ffffff)`; |
| 63 | export const vscCommandCenterActiveBorder = `var(${VSC_COMMAND_CENTER_ACTIVE_BORDER_VAR}, #1bbe84)`; |
| 64 | export const vscCommandCenterInactiveBorder = `var(${VSC_COMMAND_CENTER_INACTIVE_BORDER_VAR}, #1bbe84)`; |
| 65 | export const vscFindMatchSelected = `var(${VSC_FIND_MATCH_SELECTED_VAR}, rgba(255, 223, 0))`; |
| 66 | |
| 67 | export function parseHexColor(hexColor: string): { |
| 68 | r: number; |
| 69 | g: number; |
| 70 | b: number; |
| 71 | } { |
| 72 | if (hexColor.startsWith("#")) { |
| 73 | hexColor = hexColor.slice(1); |
| 74 | } |
| 75 | |
| 76 | if (hexColor.length > 6) { |
| 77 | hexColor = hexColor.slice(0, 6); |
| 78 | } |
| 79 | |
| 80 | const r = parseInt(hexColor.substring(0, 2), 16); |
| 81 | const g = parseInt(hexColor.substring(2, 4), 16); |
| 82 | const b = parseInt(hexColor.substring(4, 6), 16); |
| 83 | |
| 84 | return { r, g, b }; |
| 85 | } |
| 86 | |
| 87 | export function parseColorForHex(colorVar: string): string { |
| 88 | const value = getComputedStyle(document.documentElement).getPropertyValue( |
| 89 | colorVar, |
| 90 | ); |
| 91 | if (value.startsWith("#")) { |
| 92 | return value.slice(0, 7); |
| 93 | } |
| 94 | |
| 95 | // Parse rgb/rgba |
| 96 | const rgbValues = value |
| 97 | .slice(value.startsWith("rgba") ? 5 : 4, -1) |
| 98 | .split(",") |
| 99 | .map((x) => x.trim()) |
| 100 | .filter((_, i) => i < 3) // Only take the first 3 values (RGB, ignore alpha) |
| 101 | .map((x) => parseInt(x, 10)); |
| 102 | |
| 103 | let hex = |
| 104 | "#" + |
| 105 | rgbValues |
| 106 | .map((x) => x.toString(16)) |
| 107 | .map((x) => (x.length === 1 ? "0" + x : x)) |
| 108 | .join(""); |
| 109 | |
| 110 | return hex; |
| 111 | } |
| 112 | |
| 113 | export const Button = styled.button` |
| 114 | padding: 6px 12px; |
| 115 | margin: 8px 0; |
| 116 | border-radius: ${defaultBorderRadius}; |
| 117 | |
| 118 | border: none; |
| 119 | color: ${vscBackground}; |
| 120 | background-color: ${vscForeground}; |
| 121 | |
| 122 | &:disabled { |
| 123 | color: ${vscBackground}; |
| 124 | opacity: 0.5; |
| 125 | pointer-events: none; |
| 126 | } |
| 127 | |
| 128 | &:hover:enabled { |
| 129 | cursor: pointer; |
| 130 | filter: brightness(1.2); |
| 131 | } |
| 132 | `; |
| 133 | |
| 134 | export const SecondaryButton = styled.button` |
| 135 | padding: 6px 12px; |
| 136 | margin: 8px; |
| 137 | border-radius: ${defaultBorderRadius}; |
| 138 | |
| 139 | border: 1px solid ${vscInputBorder}; |
| 140 | color: ${vscForeground}; |
| 141 | background-color: ${vscInputBackground}; |
| 142 | |
| 143 | &:disabled { |
| 144 | color: gray; |
| 145 | } |
| 146 | |
| 147 | &:hover:enabled { |
| 148 | cursor: pointer; |
| 149 | background-color: ${vscBackground}; |
| 150 | opacity: 0.9; |
| 151 | } |
| 152 | `; |
| 153 | |
| 154 | export const GhostButton = styled.button` |
| 155 | padding: 6px 8px; |
| 156 | margin: 6px 0; |
| 157 | border-radius: ${defaultBorderRadius}; |
| 158 | |
| 159 | border: none; |
| 160 | color: ${vscForeground}; |
| 161 | background-color: rgba(255, 255, 255, 0.08); |
| 162 | &:disabled { |
| 163 | color: gray; |
| 164 | pointer-events: none; |
| 165 | } |
| 166 | |
| 167 | &:hover:enabled { |
| 168 | cursor: pointer; |
| 169 | filter: brightness(125%); |
| 170 | } |
| 171 | `; |
| 172 | |
| 173 | export const InputSubtext = styled.span` |
| 174 | font-size: 0.75rem; |
| 175 | line-height: 1rem; |
| 176 | color: ${lightGray}; |
| 177 | margin-top: 0.25rem; |
| 178 | `; |
| 179 | |
| 180 | export const ButtonSubtext = styled.span` |
| 181 | display: block; |
| 182 | margin-top: 0; |
| 183 | text-align: center; |
| 184 | color: ${lightGray}; |
| 185 | font-size: 0.75rem; |
| 186 | `; |
| 187 | |
| 188 | export const CustomScrollbarDiv = styled.div` |
| 189 | scrollbar-base-color: transparent; |
| 190 | scrollbar-width: thin; |
| 191 | background-color: ${vscBackground}; |
| 192 | |
| 193 | & * { |
| 194 | ::-webkit-scrollbar { |
| 195 | width: 4px; |
| 196 | } |
| 197 | |
| 198 | ::-webkit-scrollbar:horizontal { |
| 199 | height: 4px; |
| 200 | } |
| 201 | |
| 202 | ::-webkit-scrollbar-thumb { |
| 203 | border-radius: 2px; |
| 204 | } |
| 205 | } |
| 206 | `; |
| 207 | |
| 208 | export const Input = styled.input` |
| 209 | width: 100%; |
| 210 | padding: 8px 12px; |
| 211 | box-sizing: border-box; |
| 212 | margin: 4px 0px; |
| 213 | border-radius: ${defaultBorderRadius}; |
| 214 | outline: 1px solid ${lightGray}; |
| 215 | border: none; |
| 216 | background-color: ${vscBackground}; |
| 217 | color: ${vscForeground}; |
| 218 | |
| 219 | &:focus { |
| 220 | background: ${vscInputBackground}; |
| 221 | outline: 1px solid ${lightGray}; |
| 222 | } |
| 223 | |
| 224 | &:invalid { |
| 225 | outline: 1px solid red; |
| 226 | } |
| 227 | `; |
| 228 | |
| 229 | export const Label = styled.label<{ fontSize?: number }>` |
| 230 | font-size: ${(props) => props.fontSize || getFontSize()}px; |
| 231 | `; |
| 232 | |
| 233 | export const HeaderButton = styled.button<{ |
| 234 | inverted: boolean | undefined; |
| 235 | backgroundColor?: string; |
| 236 | hoverBackgroundColor?: string; |
| 237 | }>` |
| 238 | background-color: ${({ inverted, backgroundColor }) => { |
| 239 | return backgroundColor ?? (inverted ? vscForeground : "transparent"); |
| 240 | }}; |
| 241 | color: ${({ inverted }) => (inverted ? vscBackground : vscForeground)}; |
| 242 | |
| 243 | border: none; |
| 244 | border-radius: ${defaultBorderRadius}; |
| 245 | cursor: ${({ disabled }) => (disabled ? "default" : "pointer")}; |
| 246 | |
| 247 | &:focus { |
| 248 | outline: none; |
| 249 | border: none; |
| 250 | } |
| 251 | |
| 252 | &:hover { |
| 253 | background-color: ${({ inverted, hoverBackgroundColor }) => |
| 254 | typeof inverted === "undefined" || inverted |
| 255 | ? (hoverBackgroundColor ?? vscInputBackground) |
| 256 | : "transparent"}; |
| 257 | } |
| 258 | |
| 259 | display: flex; |
| 260 | align-items: center; |
| 261 | justify-content: center; |
| 262 | gap: 4px; |
| 263 | padding: 2px; |
| 264 | `; |
| 265 | |
| 266 | export const StyledActionButton = styled.div` |
| 267 | display: flex; |
| 268 | justify-content: space-between; |
| 269 | align-items: center; |
| 270 | cursor: pointer; |
| 271 | transition: background-color 200ms; |
| 272 | border-radius: ${defaultBorderRadius}; |
| 273 | padding: 2px 12px; |
| 274 | background-color: ${lightGray}33; |
| 275 | background-opacity: 0.1; |
| 276 | |
| 277 | &:hover { |
| 278 | background-color: ${lightGray}55; |
| 279 | } |
| 280 | `; |
| 281 | |
| 282 | export const CloseButton = styled.button` |
| 283 | border: none; |
| 284 | background-color: inherit; |
| 285 | color: ${lightGray}; |
| 286 | position: absolute; |
| 287 | top: 0.6rem; |
| 288 | right: 1rem; |
| 289 | padding: 0.25rem; |
| 290 | display: flex; |
| 291 | align-items: center; |
| 292 | justify-content: center; |
| 293 | cursor: pointer; |
| 294 | `; |
| 295 | |
| 296 | export const AnimatedEllipsis = styled.span` |
| 297 | &::after { |
| 298 | content: "."; |
| 299 | animation: ellipsis 2.5s infinite; |
| 300 | display: inline-block; |
| 301 | width: 12px; |
| 302 | text-align: left; |
| 303 | } |
| 304 | |
| 305 | @keyframes ellipsis { |
| 306 | 0% { |
| 307 | content: "."; |
| 308 | } |
| 309 | 33% { |
| 310 | content: ".."; |
| 311 | } |
| 312 | 66% { |
| 313 | content: "..."; |
| 314 | } |
| 315 | } |
| 316 | `; |