Skip to content

Commit

Permalink
chore: fix snippet-preview style
Browse files Browse the repository at this point in the history
  • Loading branch information
codemaster115 committed Sep 19, 2023
1 parent 19c4e28 commit 1c04301
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/quo2/components/code/common/style.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
nil))

(defn text-style
[class-names]
[class-names preview?]
(let [text-color (->> class-names
(map keyword)
(some (fn [class-name]
(when-let [text-color (theme class-name)]
text-color))))]
(cond-> {:flex-shrink 1
:line-height 18}
preview? (assoc :color colors/white)
text-color (assoc :color text-color))))

(defn border-color
Expand All @@ -37,7 +38,7 @@
(if preview?
{:overflow :hidden
:width 108
:background-color (colors/theme-colors colors/neutral-20 colors/neutral-80 theme)
:background-color (colors/theme-colors colors/neutral-20 colors/neutral-80 :dark)
:border-radius 8}
{:overflow :hidden
:padding 8
Expand All @@ -64,7 +65,7 @@
:width (+ line-number-width 8 7)
:background-color (colors/theme-colors colors/neutral-5 colors/neutral-80)}
preview? (assoc :width 20
:background-color (colors/theme-colors colors/neutral-10 colors/neutral-70 theme))))
:background-color (colors/theme-colors colors/neutral-10 colors/neutral-70 :dark))))

(defn divider
[line-number-width]
Expand Down
12 changes: 6 additions & 6 deletions src/quo2/components/code/common/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
[reagent.core :as reagent]))

(defn- render-nodes
[nodes]
[nodes preview?]
(map (fn [{:keys [children value last-line?] :as node}]
(if children
(into [text/text
(cond-> {:weight :code
:size :paragraph-2
:style (style/text-style (get-in node [:properties :className]))}
:style (style/text-style (get-in node [:properties :className]) preview?)}
last-line? (assoc :number-of-lines 1))]
(render-nodes children))
(render-nodes children preview?))
;; Remove newlines as we already render each line separately.
(string/trim-newline value)))
nodes))
Expand All @@ -28,7 +28,7 @@
[rn/view {:style style/line}
[rn/view {:style (style/line-number line-number-width preview?)}
[text/text
{:style (style/text-style ["line-number"])
{:style (style/text-style ["line-number"] preview?)
:weight :code
:size :paragraph-2}
line-number]]
Expand All @@ -38,8 +38,8 @@
(defn- code-block
[{:keys [rows line-number-width preview?]}]
[rn/view
(->> rows
(render-nodes)
(->> preview?
(render-nodes ,, rows)
(map-indexed (fn [idx row-content]
[line
{:line-number (inc idx)
Expand Down

0 comments on commit 1c04301

Please sign in to comment.