This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-13
Channels
- # adventofcode (36)
- # aleph (1)
- # announcements (7)
- # aws (4)
- # babashka (14)
- # beginners (61)
- # calva (79)
- # cider (19)
- # clojure (48)
- # clojure-austin (1)
- # clojure-australia (2)
- # clojure-czech (2)
- # clojure-europe (46)
- # clojure-france (8)
- # clojure-nl (19)
- # clojure-uk (4)
- # clojuredesign-podcast (14)
- # core-logic (42)
- # data-science (3)
- # datalevin (8)
- # datomic (76)
- # events (1)
- # figwheel-main (9)
- # fulcro (6)
- # helix (1)
- # holy-lambda (1)
- # honeysql (2)
- # jobs (2)
- # jobs-discuss (20)
- # leiningen (5)
- # lsp (87)
- # minecraft (11)
- # nextjournal (4)
- # off-topic (17)
- # practicalli (1)
- # reagent (22)
- # reitit (8)
- # releases (3)
- # rum (2)
- # shadow-cljs (18)
- # sql (11)
- # tools-build (5)
- # tools-deps (9)
- # xtdb (20)
I've found the emotion css-in-js tool (https://emotion.sh/docs/styled) mixes really well with cljs - data driven all the way:
(defstyled multi :div
{:background "blue"}
{:color "yellow"}
#js{"borderRadius" 4}
[{"border" "1px solid grey"}]
(fn [_] {":hover" {:background "white"}}))
In this example all those styles are merged together - this way you can have a collection of styles as maps/vectors (or functions of props -> map of styles) and then combine them profitably at runtime however you like. This code is using a wrapper for emotion that I authored: https://github.com/dvingo/cljs-emotion but most of the work is done in emotion proper - there are classnames under the hood, but those are transparent to you. This macro produces a react component which, when rendered, inserts the styles and assigns the resulting react element the generated class name.
There is also anonymous style support so if you don't want to def
anything, you don't have to:
(defn anon-styles []
(css :div {:css {:background "lightgrey"}}
"Some text on a lightgrey background."))
@U051V5LLP Why use something other then a clojure hashmap as a child?
(defstyled sample1 :div
{:background-color "RebeccaPurple"}
#js{:color "yellow"}
(fn [props] {:border-radius 4}))
so here normally a media query has to be in a css file and can't be on a html attribute, thats the -in-js part right? the var is just to show you can right, the important bit is the "global-style" function right?
(def mw-700 "@media (min-width:700px)")
[:div
[:.my-thing "Some content"]
(global-style
{:.my-thing {:background "navy" :color "#cce" mw-700 {:background "black"}}})])
How does this compare with getting the screen with from javascript, i'm guessing js is slower, but i never really looked into confirming it.
when is :component-will-unmount
called?
I have a timer component that I’m updating with js/setInterval
, and I have js/clearInterval
in the :component-will-unmount
, but I can’t seem to get the clearInterval
call to happen when the component stops rendering
nevermind! false alarm. I had (js/clearInterval interval)
instead of (js/clearInterval @interval)
Hello everyone I’m trying to translate this snippet into ClojureScript:
const ExpandMore = styled((props) => {
const { expand, ...other } = props;
return <IconButton {...other} />;
})(({ theme, expand }) => ({
transform: !expand ? 'rotate(0deg)' : 'rotate(180deg)',
marginLeft: 'auto',
transition: theme.transitions.create('transform', {
duration: theme.transitions.duration.shortest,
}),
}));
But, I’m getting this error:
Error: Objects are not valid as a React child (found: object with keys {tag, id, className, displayName}). If you meant to render a collection of children, use an array instead.
And I’m having no idea on what I’m doing wrong 😞
¿Could someone help? This is my translation:
(ns foo
(:require
[reagent-mui.material.icon-button :refer [icon-button]]
[reagent-mui.styles :refer [styled]]))
...
(defn expand-more
[{:keys [expand] :as props}]
(let [props (dissoc props :expand)]
(styled icon-button
props
{:margin-left :auto
:transform (if expand "rotate(0deg)" "rotate(180deg)")
:transition #(let [{:keys [create duration]} (-> ^js/Object % .-transitions (js->clj :keywordize-keys true))]
(create "transform" #js{:duration (:shortest duration)}))})))
...
;; There is some example of how I'm calling it:
(defn component
[]
(r/with-let [expanded? (r/atom false)]
[expand-more {:expand @expanded?
:on-click #(swap! expanded? not)
:aria-label "Show more"
:aria-expanded @expanded?}]))
Original code: ExpandMore = styled(...)
.
Your code: (defn expand-more [...] (styled ...))
.
Do you see the difference?
The original code wraps the function with styled
and assigns the result to a name.
Your code creates a function that calls style
inside of it and assigns the function - not its result! - to a name.
Nope, I still don’t get it. In the original example they used ExpandMore
as a React Component:
<ExpandMore
expand={expanded}
onClick={handleExpandClick}
aria-expanded={expanded}
aria-label="show more"
>
<ExpandMoreIcon />
</ExpandMore>
expand-more
should be a reagent component¿Does expand-more
should be
(defn expand-more
[{:keys [expand] :as props} & body]
...)
?By using (def expand-more (styled ...))
, you already make sure that expand-more
is a Reagent component.
I almost got it, but it does not show anything:
(def expand-more
(styled (fn [props & body]
[icon-button (dissoc props :expand) body])
(fn [theme expand]
(let [create-fn (get-in theme [:theme :transitions :create])
duration (get-in theme [:theme :transitions :duration])]
{:margin-left :auto
:transform (if (:expand expand) "rotate(180deg)" "rotate(0deg)")
:transition (create-fn "transform" #js{:duration (:shortest duration)})}))))
props
is:
{:expand false, :on-click #object[Function], :aria-label Expandir detalle de fechas, :aria-expanded false, :children #object[reagent.impl.template.NativeWrapper], :class-name css-1tj6xfp, :ref nil}