Fork me on GitHub
#clojurescript
<
2023-04-30
>
Stpn19:04:41

Hello! I am trying to use React component in cljs+reagent. It is not hard, but I struggle with a reference to an inner react field (so to speak). In typescript it should like this: <MDEditor value={value} onChange={setValue}/> <MDEditor.Markdown source={value} style={{ whiteSpace: 'pre-wrap' }} /> and in cljs I try this: [:> MDEditor {:value @value :on-change #(reset! value %)}] [:> MDEditor.Markdown {:source @value :style "whiteSpace: 'pre-wrap'"}] the first line is OK (it works), but when I add second - it breaks. How to use MDEditor.Markdown here?

Sam Ritchie21:04:45

Probably (.-Markdown MDEditor)?

Sam Ritchie21:04:14

Oh and make style a map not a string

BuddhiLW23:04:33

I'm having issues translating '&:hover' Material-UI prop to ClojureScript. How am I supposed to do it? I want to change the color of the background of the text, when I hover over it.

(ns playground.core
    (:require
     ["@mui/material" :refer [Typography]]))

  [:> Typography {:variant "h2"
                  :font-size "1.3em"
                  :color {:color "palette.primary.secondary"}
                  :&:hover {:backgroundColor "primary.tertiary"} ;; <--- throws error
                  :background "palette.primary.main"}
   "Hello typography!"])
From https://mui.com/material-ui/react-box/,
import * as React from 'react';
import Box from '@mui/material/Box';

export default function BoxSx() {
  return (
    <Box
      sx={{
        width: 300,
        height: 300,
        backgroundColor: 'primary.dark',
        '&:hover': {
          backgroundColor: 'primary.main',
          opacity: [0.9, 0.8, 0.7],
        },
      }}
    />
  );
}
The error:
Warning: Invalid attribute name: `&:hover
`

p-himik23:04:53

Just pass a string, "&:hover".

p-himik23:04:11

Also note that those examples are not compatible. The JSX one wraps all its style properties in the sx property. Whereas your CLJS code passes all type properties at the top level.

BuddhiLW23:04:57

Still, throws: Warning: Invalid attribute name: &:hover``

BuddhiLW23:04:31

Can I use sx with clojurescript? I wouldn't know how to do it.

p-himik23:04:32

Same way you used all other properties. Maybe its value needs to be wrapped in clj->js, not sure. Try without it first.

BuddhiLW23:04:41

Alright, that did it. I mixed both: {:sx {"&:hover" {:backgroundColor ...}}} and it works. Thanks @U2FRKM4TW

👍 2
p-himik23:04:38

BTW :background-color should also work.

BuddhiLW00:05:46

Oh yeah, kebab to camel, I'm aware! Will make it kebab to keep it clojure

hifumi12302:05:11

I recommend using reagent-material-ui if you'd like a wrapper that lets you write hiccup and use props exactly as you would in CLJS. It's a really great library

hifumi12302:05:00

It handles all of the JS object conversion and case changing for you, and besides a few r/as-element calls, the abstractions don't really leak