feat: eww design tokens

This commit is contained in:
hesam-init 2024-07-01 18:33:10 +03:30
parent 4a088d2f91
commit 49bd527e28
9 changed files with 82 additions and 51 deletions

View file

@ -3,8 +3,6 @@
} }
.reveal-on-click { .reveal-on-click {
@include font("medium");
color: $surface2; color: $surface2;
padding: 4px 0px; padding: 4px 0px;
} }

View file

@ -1,34 +1,20 @@
@mixin font($size: "default") { @import "tokens";
$sizes: (
"small": 16px,
"medium": 18px,
"large": 20px,
);
@if map-has-key($sizes, $size) {
font-size: map-get($sizes, $size);
} @else {
font-size: map-get($sizes, "large");
}
}
@mixin widget() { @mixin widget() {
padding: 0.6em 0.4em; padding: get-token(padding, small);
margin: 4px 2px; margin: get-token(margin);
border-radius: 8px; border-radius: get-token(border-radius);
background-color: $surface0; background-color: $surface0;
} }
@mixin icon() { @mixin icon() {
@include font("medium"); font-size: get-token(font-sizes);
font-family: "Symbols Nerd Font"; font-family: "Symbols Nerd Font";
} }
@mixin popup() { @mixin popup() {
background-color: $base; padding: get-token(padding, small);
padding: 8px; border-radius: get-token(border-radius);
border-radius: 12px; margin: get-token(margin);
border-style: solid; background-color: $surface1;
margin: 10px;
} }

View file

@ -1,17 +1,9 @@
.clock { .clock {
@include widget; @include widget;
label {
@include font;
}
} }
.language { .language {
@include widget; @include widget;
label {
@include font("small");
}
} }
.logo { .logo {

View file

@ -0,0 +1,46 @@
$design-tokens: (
font-sizes: (
small: 16px,
default: 18px,
large: 20px,
),
padding: (
small: 8px,
default: 10px,
large: 12px,
),
margin: (
small: 2px,
default: 4px,
large: 6px,
),
border-radius: (
small: 6px,
default: 8px,
large: 12px,
),
);
@function get-token($category, $key: null) {
$tokens: map-get($design-tokens, $category);
@if $tokens == null {
@error "Category `#{$category}` not found in design tokens.";
}
@if $key == null {
@if map-has-key($tokens, default) {
$key: default;
} @else {
@error "Default key not found in category `#{$category}`.";
}
}
$value: map-get($tokens, $key);
@if $value == null {
@error "Token `#{$key}` not found in category `#{$category}`.";
}
@return $value;
}

View file

@ -9,7 +9,7 @@
:transition "slideleft" :transition "slideleft"
(children :nth 1)))) (children :nth 1))))
(defwidget RevealOnHover [var varname ?class ?duration ?transition ?icon] (defwidget RevealOnHover [var varname ?icon ?class ?duration ?transition]
(eventbox (eventbox
:onhover `${EWW_CMD} update ${varname}=true` :onhover `${EWW_CMD} update ${varname}=true`
:onhoverlost `${EWW_CMD} update ${varname}=false` :onhoverlost `${EWW_CMD} update ${varname}=false`
@ -22,7 +22,7 @@
(revealer (revealer
:reveal var :reveal var
:transition {transition ?:"slidedown"} :transition {transition ?:"slidedown"}
:duration "500ms" :duration animation-duration-default
(box :class "reveal-on-hover" (children :nth 0)))) (box :class "reveal-on-hover" (children :nth 0))))
)) ))
@ -35,7 +35,7 @@
(revealer (revealer
:reveal var :reveal var
:transition "slideup" :transition "slideup"
:duration "500ms" :duration animation-duration-fast
(box (children :nth 0))) (box (children :nth 0)))
(eventbox (eventbox

View file

@ -4,7 +4,7 @@
(box (box
:class "widget" :class "widget"
:orientation "v" :orientation "v"
:spacing defaultSpacing :spacing spacing-default
(eventbox (eventbox
:onclick "${EWW_CMD} open MusicPlayerPopup --toggle" :onclick "${EWW_CMD} open MusicPlayerPopup --toggle"

View file

@ -9,20 +9,20 @@
:class "workspaces" :class "workspaces"
:space-evenly false :space-evenly false
:orientation "v" :orientation "v"
:spacing largeSpacing :spacing spacing-default
(for workspace in {workspacesJson} (for workspace in {workspacesJson}
(button (button
:onclick "hyprctl dispatch workspace ${workspace.id}" :onclick "hyprctl dispatch workspace ${workspace.id}"
(box (box
:height 25 :height 20
:class "workspace ${workspace.id == currentWorkspace ? "workspacethingactive" : "workspacething"}" :class "workspace ${workspace.id == currentWorkspace ? "workspacethingactive" : "workspacething"}"
(revealer (revealer
:reveal { workspace.id == currentWorkspace} :reveal { workspace.id == currentWorkspace}
:transition "slideup" :transition "slidedown"
:duration 500 :duration animation-duration-default
(box (box
:height 40)))))))) :height 40))))))))

View file

@ -1,9 +1,14 @@
; Global Styles ; Global Styles
(defvar animationDuration "500ms") (defvar animation-duration-default "600ms")
(defvar defaultSpacing 8) (defvar animation-duration-slow "1000ms")
(defvar largeSpacing 6) (defvar animation-duration-fast "400ms")
(defvar mediumSpacing 4) (defvar animation-duration-very-fast "200ms")
(defvar smallSpacing 2)
(defvar spacing-default 8)
(defvar spacing-large 16)
(defvar spacing-medium 8)
(defvar spacing-small 4)
(defvar spacing-tiny 2)
; Global ; Global
(deflisten kbLayout :initial "en" "./scripts/kb-layout/get-active") (deflisten kbLayout :initial "en" "./scripts/kb-layout/get-active")

View file

@ -7,6 +7,8 @@
(revealer (revealer
:transition "slideleft" :transition "slideleft"
:reveal revealControlpanel :reveal revealControlpanel
:duration animation-duration-default
(ControlPanel)) (ControlPanel))
(centerbox (centerbox
@ -26,7 +28,7 @@
(Logo) (Logo)
(Workspaces) (Workspaces)
(hiddenctl) ;; (Shortcuts)
)) ))
(defwidget Middle [] (defwidget Middle []
@ -34,7 +36,7 @@
:orientation "v" :orientation "v"
:space-evenly false :space-evenly false
:valign "center" :valign "center"
:height 240 :height 200
(PlayerCtl) (PlayerCtl)
)) ))
@ -90,14 +92,16 @@
:text "󱐋")) :text "󱐋"))
(label :text "${EWW_BATTERY.BAT0.capacity}%" :limit-width 3 :show-truncated false))) (label :text "${EWW_BATTERY.BAT0.capacity}%" :limit-width 3 :show-truncated false)))
(defwidget hiddenctl [] (defwidget Shortcuts []
(RevealOnClick (RevealOnClick
:var reveal3 :var reveal3
:varname "reveal3" :varname "reveal3"
(box (box
:class "touch" :class "touch"
:orientation "v" :orientation "v"
:spacing 5 :spacing spacing-default
(button :onclick "swaymsg kill" (button :onclick "swaymsg kill"
(label :class "icon" :text "󰅙")) (label :class "icon" :text "󰅙"))
(button :onclick "wofi --show=drun -i -I" (button :onclick "wofi --show=drun -i -I"
@ -111,7 +115,7 @@
:class "widget" :class "widget"
:orientation "v" :orientation "v"
:space-evenly false :space-evenly false
:spacing defaultSpacing :spacing spacing-default
:valign "end" :valign "end"
(button :onclick "alacritty -e nmtui" :tooltip wifi_essid (button :onclick "alacritty -e nmtui" :tooltip wifi_essid