0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-12 18:18:24 -05:00

Assert existing icon ID for button* and icon-button*

This commit is contained in:
Belén Albeza 2024-07-26 11:55:43 +02:00
parent 10ef9d696c
commit cfc01e03f6
5 changed files with 12 additions and 19 deletions

View file

@ -9,7 +9,7 @@
[app.common.data.macros :as dm]
[app.main.style :as stl])
(:require
[app.main.ui.ds.foundations.assets.icon :refer [icon*]]
[app.main.ui.ds.foundations.assets.icon :refer [icon* icon-list]]
[rumext.v2 :as mf]))
(def button-variants (set '("primary" "secondary" "ghost" "destructive")))
@ -18,6 +18,7 @@
{::mf/props :obj}
[{:keys [variant icon children class] :rest props}]
(assert (or (nil? variant) (contains? button-variants variant) "expected valid variant"))
(assert (or (nil? icon) (contains? icon-list icon) "expected valid icon id"))
(let [variant (or variant "primary")
class (dm/str class " " (stl/css-case :button true
:button-primary (= variant "primary")

View file

@ -10,18 +10,12 @@ import Components from "@target/components";
const { Button } = Components;
const { icons } = Components.meta;
const iconList = [
...Object.entries(icons)
.map(([_, value]) => value)
.sort(),
];
export default {
title: "Buttons/Button",
component: Components.Button,
argTypes: {
icon: {
options: iconList,
options: icons,
control: { type: "select" },
},
disabled: { control: "boolean" },

View file

@ -9,7 +9,7 @@
[app.common.data.macros :as dm]
[app.main.style :as stl])
(:require
[app.main.ui.ds.foundations.assets.icon :refer [icon*]]
[app.main.ui.ds.foundations.assets.icon :refer [icon* icon-list]]
[rumext.v2 :as mf]))
(def button-variants (set '("primary" "secondary" "ghost" "destructive")))
@ -17,9 +17,9 @@
(mf/defc icon-button*
{::mf/props :obj}
[{:keys [class icon variant aria-label] :rest props}]
(assert (or (not variant) (contains? button-variants variant)) "invalid variant")
(assert (contains? icon-list icon) "expected valid icon id")
(assert (or (not variant) (contains? button-variants variant)) "expected valid variant")
(assert (some? aria-label) "aria-label must be provided")
(assert (some? icon) "an icon id must be provided")
(let [variant (or variant "primary")
class (dm/str class " " (stl/css-case :icon-button true
:icon-button-primary (= variant "primary")

View file

@ -7,12 +7,11 @@
(ns app.main.ui.ds.foundations.assets.icon
(:require
[clojure.core :as c]
[cuerdas.core :as str]
[rumext.v2]))
(defmacro collect-icons []
(let [ns-info (:ns &env)]
`(set '~(->> (:defs ns-info)
(map val)
(filter (fn [entry] (-> entry :meta :icon-id)))
(map (fn [{:keys [name]}] (c/name name)))))))
(map val)
(filter (fn [entry] (-> entry :meta :icon-id)))
(map (fn [{:keys [name]}] (c/name name)))))))

View file

@ -7,12 +7,11 @@
(ns app.main.ui.ds.foundations.assets.raw-svg
(:require
[clojure.core :as c]
[cuerdas.core :as str]
[rumext.v2]))
(defmacro collect-raw-svgs []
(let [ns-info (:ns &env)]
`(set '~(->> (:defs ns-info)
(map val)
(filter (fn [entry] (-> entry :meta :svg-id)))
(map (fn [{:keys [name]}] (c/name name)))))))
(map val)
(filter (fn [entry] (-> entry :meta :svg-id)))
(map (fn [{:keys [name]}] (c/name name)))))))