2023-06-27 15:34:12 +00:00
|
|
|
import { ColorScheme } from "../common";
|
2023-06-27 16:24:19 +00:00
|
|
|
import { interactive, toggleable } from "../element";
|
2023-06-27 15:34:12 +00:00
|
|
|
import { background, foreground } from "../styleTree/components";
|
2023-06-27 20:20:45 +00:00
|
|
|
|
|
|
|
export type Margin = {
|
|
|
|
top: number;
|
|
|
|
bottom: number;
|
|
|
|
left: number;
|
|
|
|
right: number;
|
|
|
|
}
|
2023-06-27 15:34:12 +00:00
|
|
|
|
|
|
|
interface IconButtonOptions {
|
2023-06-27 16:24:19 +00:00
|
|
|
layer?: ColorScheme['lowest'] | ColorScheme['middle'] | ColorScheme['highest'];
|
2023-06-27 15:34:12 +00:00
|
|
|
color?: keyof ColorScheme['lowest'];
|
|
|
|
margin?: Partial<Margin>;
|
|
|
|
}
|
|
|
|
|
2023-06-27 16:24:19 +00:00
|
|
|
type ToggleableIconButtonOptions = IconButtonOptions & { active_color?: keyof ColorScheme['lowest'] };
|
|
|
|
|
|
|
|
export function icon_button(theme: ColorScheme, { color, margin, layer }: IconButtonOptions) {
|
2023-06-27 15:34:12 +00:00
|
|
|
if (!color)
|
|
|
|
color = "base";
|
|
|
|
|
|
|
|
const m = {
|
|
|
|
top: margin?.top ?? 0,
|
|
|
|
bottom: margin?.bottom ?? 0,
|
|
|
|
left: margin?.left ?? 0,
|
|
|
|
right: margin?.right ?? 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
return interactive({
|
|
|
|
base: {
|
2023-06-27 16:24:19 +00:00
|
|
|
corner_radius: 6,
|
2023-06-27 15:34:12 +00:00
|
|
|
padding: {
|
|
|
|
top: 2,
|
|
|
|
bottom: 2,
|
|
|
|
left: 4,
|
|
|
|
right: 4,
|
|
|
|
},
|
|
|
|
margin: m,
|
2023-06-28 14:19:30 +00:00
|
|
|
icon_width: 14,
|
|
|
|
icon_height: 14,
|
|
|
|
button_width: 20,
|
|
|
|
button_height: 16,
|
2023-06-27 15:34:12 +00:00
|
|
|
},
|
|
|
|
state: {
|
|
|
|
default: {
|
2023-06-27 16:24:19 +00:00
|
|
|
background: background(layer ?? theme.lowest, color),
|
|
|
|
color: foreground(layer ?? theme.lowest, color),
|
2023-06-27 15:34:12 +00:00
|
|
|
},
|
|
|
|
hovered: {
|
2023-06-27 16:24:19 +00:00
|
|
|
background: background(layer ?? theme.lowest, color, "hovered"),
|
|
|
|
color: foreground(layer ?? theme.lowest, color, "hovered"),
|
2023-06-27 15:34:12 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
clicked: {
|
2023-06-27 16:24:19 +00:00
|
|
|
background: background(layer ?? theme.lowest, color, "pressed"),
|
|
|
|
color: foreground(layer ?? theme.lowest, color, "pressed"),
|
2023-06-27 15:34:12 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2023-06-27 16:24:19 +00:00
|
|
|
|
|
|
|
export function toggleable_icon_button(theme: ColorScheme, { color, active_color, margin }: ToggleableIconButtonOptions) {
|
|
|
|
if (!color)
|
|
|
|
color = "base";
|
|
|
|
|
|
|
|
return toggleable({
|
|
|
|
state: {
|
|
|
|
inactive: icon_button(theme, { color, margin }),
|
|
|
|
active: icon_button(theme, { color: active_color ? active_color : color, margin, layer: theme.middle }),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|