garden

manandearth 2019-01-15T19:57:29.005300Z

Looking for an example for tool-tips. I am using re-frame with garden and I can't manage to crack this... Basically I have an svg element something like :

[:svg [:g [:circle :r (some-value) :cx (some-other-value) ,,,]]]
and I'd like to have a stylised tool-tip with some logic on hover. can't get my head around it...

idiomancy 2019-01-15T20:02:18.005600Z

what would it look like in normal CSS?

manandearth 2019-01-15T20:11:28.008Z

Just an example I just borrowed from https://github.com/jacekschae/learn-reagent-course-files/blob/master/increments/complete/public/css/style.css

/* = Tooltip = */

.tooltip {
  position: relative;
}

.tooltip::after {
  background: rgba(69, 77, 93, .9);
  border-radius: 6px;
  color: #fff;
  content: attr(data-tooltip);
  display: block;
  font-size: .8rem;
  max-width: 320px;
  opacity: 0;
  overflow: hidden;
  padding: .3rem .5rem;
  pointer-events: none;
  position: absolute;
  text-overflow: ellipsis;
  transform: translate(-50%, .4rem);
  transition: all .2s ease;
  white-space: pre;
  z-index: 300;
	bottom: 50%;
  left: auto;
  right: 100%;
  transform: translate(.4rem, 50%);
}

.tooltip:focus::after,
.tooltip:hover::after {
  opacity: 1;
  transform: translate(-.2rem, 50%);
}

.tooltip[disabled],
.tooltip.disabled {
  pointer-events: auto;
}

manandearth 2019-01-15T20:11:58.008300Z

It can be simpler. I just want to understand the principle. Is it a class? and where is it defined as a tool-tip?

idiomancy 2019-01-15T20:28:55.009700Z

they're applying the .tooltip class to some element, probably just statically, with no js manipulation

idiomancy 2019-01-15T20:29:15.010200Z

because its set to opacity 0 when you're not hovering over it

idiomancy 2019-01-15T20:32:53.012100Z

so, in reframe, your hiccup would have something like

[:div 
   [:svg [:g [:circle :r (some-value) :cx (some-other-value) ,,,]]]
   [:div.toopltip "its an image"]
]

manandearth 2019-01-15T20:33:32.012500Z

the element that uses that class in the example is:

[:div.btn.btn--primary.float--right.tooltip
                       {:data-tooltip "Add to order"
                        :on-click #(add-to-order id)}
                       [:i.icon.icon--plus]]

manandearth 2019-01-15T20:33:58.012900Z

so how will the garden version look like?

manandearth 2019-01-15T20:34:36.013300Z

for the .tooltip class I mean

idiomancy 2019-01-15T20:35:47.013900Z

gotcha. well, let me take a crack at translating that css to garden

idiomancy 2019-01-15T20:36:14.014500Z

the only thing im not sure about is the [disabled] selector

idiomancy 2019-01-15T20:36:24.015Z

not sure how that works in garden

manandearth 2019-01-15T20:36:24.015100Z

just the basics....

manandearth 2019-01-15T20:36:36.015500Z

What is the disabled anyway?

idiomancy 2019-01-15T20:37:41.015900Z

its an attribute selector https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors

idiomancy 2019-01-15T20:38:27.016700Z

so its saying it selects an html element that has a class .tooltip and an attribute [disabled]

idiomancy 2019-01-15T20:39:01.017300Z

or an element that has both the .tooltip and .disabled classes

manandearth 2019-01-15T20:40:47.017900Z

I see...

idiomancy 2019-01-15T20:41:08.018400Z

so for the basics, something like

.tooltip {
  position: relative;
}
becomes [:.tooltip {:position :relative}]

idiomancy 2019-01-15T20:41:54.019800Z

keep in mind, garden is literally just compiling to CSS, its not really doing anything more than the CSS is doing

manandearth 2019-01-15T20:42:43.020600Z

What I don't understand is what attribute defines the element as an actual tooltip? since the class .tooltip is just a user defined var, no?

idiomancy 2019-01-15T20:45:19.022500Z

hahaha, I'm not sure if I completely understand the question, which is normal because CSS work is weird, but I'll give a few cracks at answering it to narrow down the space

idiomancy 2019-01-15T20:45:53.023200Z

so, the thing that identifies the element as being a tooltip is this in the hiccup: :div.btn.btn--primary.float--right .tooltip

idiomancy 2019-01-15T20:46:40.023500Z

ohhh

idiomancy 2019-01-15T20:46:41.023700Z

I see

idiomancy 2019-01-15T20:46:43.023900Z

I see

idiomancy 2019-01-15T20:46:46.024200Z

okay

idiomancy 2019-01-15T20:46:52.024500Z

yeah, theres a missing piece

idiomancy 2019-01-15T20:47:47.025200Z

okay, I get it now

idiomancy 2019-01-15T20:47:53.025400Z

alright, you ready for this?

idiomancy 2019-01-15T20:47:59.025800Z

I didn't even know you could do this

manandearth 2019-01-15T20:48:09.026100Z

yes!

idiomancy 2019-01-15T20:49:22.027500Z

so. hes marking the item he wants a tooltip: the ':div.btn' with a .tooltip class. then, instead of making a second element in the html that is marked as a tooltip, he adds this guy:

idiomancy 2019-01-15T20:49:38.027700Z

:data-tooltip "Add to order"

idiomancy 2019-01-15T20:50:16.028300Z

any html attribute that starts with data-whatever is just arbitrary user defined data - has no meaning to the browser

idiomancy 2019-01-15T20:50:53.029200Z

so, what he's doing is creating an html element in the CSS that is the actual tooltip

idiomancy 2019-01-15T20:51:20.029700Z

thats what pseudoselectors do -- they create an element relative to some known element

manandearth 2019-01-15T20:51:25.030Z

right...

idiomancy 2019-01-15T20:51:53.030600Z

in this case, he's using the pseudoselector ::after, and then for the text of that element, hes referring to content: attr(data-tooltip);

idiomancy 2019-01-15T20:52:11.031100Z

which I didn't know you could do. I didn't know you could pass data into the css from the html

idiomancy 2019-01-15T20:52:46.031700Z

so, the .tooltip::after defined in the CSS is the tooltip

idiomancy 2019-01-15T20:53:01.032Z

thats the CSS and the html element that contains it defined at once

manandearth 2019-01-15T20:53:53.033100Z

is that a .tooltip:&:after in garden?

idiomancy 2019-01-15T20:54:06.033300Z

yeah, I believe so

manandearth 2019-01-15T20:54:21.033700Z

right, I'll try to reconstruct it.

idiomancy 2019-01-15T20:54:27.033900Z

its been a while though, let me check the wiki

idiomancy 2019-01-15T20:57:30.034100Z

I use this page a lot

idiomancy 2019-01-15T20:58:01.034700Z

looks like it actually works like this @adamgefen [:div [:&:hover {:color "blue"}]]

idiomancy 2019-01-15T20:58:13.035Z

you put it in a child vector

idiomancy 2019-01-15T20:58:34.035400Z

the & refers to the value of the root of the parent vector

idiomancy 2019-01-15T20:59:01.035700Z

(s/div :.quote (s/after))

idiomancy 2019-01-15T20:59:13.036Z

after elements are defined using functions

idiomancy 2019-01-15T21:00:20.037100Z

lol, sorry, Im just piecing this back together myself. its been a while since ive been in front end

manandearth 2019-01-15T21:00:44.037400Z

ok. I need to get my head round this one. I've only defined defstylesheet in garden so far...

idiomancy 2019-01-15T21:01:27.038Z

gotcha, so do you have it compiling to a stylesheet or anything yet?

idiomancy 2019-01-15T21:02:27.039100Z

might be helful to just evaluate (garden.core/css ....) with your code in the repl for a while, see what it produces

idiomancy 2019-01-15T21:02:44.039600Z

it outputs the text of the css

manandearth 2019-01-15T21:04:20.041200Z

yes. a:

(defstylesheet screen
{:output-to "resources/public/css/screen.css"}
,,,
;;followed by all the css classes in garden syntax
)

manandearth 2019-01-15T21:05:19.041600Z

good advice, thanks!

chadhs 2019-01-15T22:24:25.042400Z

does anyone know how to convert this type of reference to garden from css

input[type=text]{
.....
}

chadhs 2019-01-15T22:24:30.042600Z

can’t for the life of me figure it out

niamu 2019-01-15T22:29:10.043400Z

@chadhs [:input (garden.selectors/attr= :type :text) {...}]

chadhs 2019-01-15T22:31:04.043600Z

@niamu thanks!

niamu 2019-01-15T22:34:04.045300Z

No problem. That’s a bit of a trickier one with garden. I personally refer to my own cljc-normalize (https://github.com/powernoodle/cljc-normalize) project which is as faithful a garden representation as I can make for normalize.css.