|
1000 | 1000 |
|
1001 | 1001 | (defonce ^:no-doc hover? (r/atom nil))
|
1002 | 1002 |
|
1003 |
| -(defn- hover-border [context] |
| 1003 | +(defn- multi-select-counter [context] |
| 1004 | + (let [theme (theme/use-theme) |
| 1005 | + selected (:selected (use-options)) |
| 1006 | + state (state/use-state) |
| 1007 | + background (get-background) |
| 1008 | + multi? @(r/track #(> (count (:selected @state)) 1))] |
| 1009 | + (when (and multi? selected) |
| 1010 | + [s/div {:style |
| 1011 | + {:position :absolute |
| 1012 | + :font-size "0.8rem" |
| 1013 | + :color background |
| 1014 | + :border-radius 100 |
| 1015 | + :top "-0.5rem" |
| 1016 | + :right "-0.5rem" |
| 1017 | + :min-width "1rem" |
| 1018 | + :height "1rem" |
| 1019 | + :display :flex |
| 1020 | + :align-items :center |
| 1021 | + :justify-content :center |
| 1022 | + :background (get theme (nth theme/order (:depth context)))}} |
| 1023 | + selected]))) |
| 1024 | + |
| 1025 | +(defn- inspector-border [context] |
1004 | 1026 | (let [theme (theme/use-theme)
|
1005 | 1027 | selected (:selected (use-options))
|
1006 |
| - hover (and (not selected) |
1007 |
| - (not (:readonly? context)) |
1008 |
| - @(r/track #(= % @hover?) context))] |
1009 |
| - [s/div |
1010 |
| - {:style |
1011 |
| - {:position :absolute |
1012 |
| - :pointer-events :none |
1013 |
| - :z-index 2 |
1014 |
| - :top 0 |
1015 |
| - :left 0 |
1016 |
| - :right 0 |
1017 |
| - :bottom 0 |
1018 |
| - :opacity 0.75 |
1019 |
| - :border-radius (:border-radius theme) |
1020 |
| - :background (when hover "rgba(0,0,0,0.15)") |
1021 |
| - :transition "border 0.35s, background 0.35s" |
1022 |
| - :border [1 :solid (if-not hover |
1023 |
| - "rgba(0,0,0,0)" |
1024 |
| - (get theme (nth theme/order (:depth context))))]}}])) |
| 1028 | + hover (and (not (:readonly? context)) |
| 1029 | + @(r/track #(= % @hover?) context)) |
| 1030 | + color (get theme (nth theme/order (:depth context))) |
| 1031 | + transition "border 0.35s, background 0.35s, box-shadow 0.35s, border-radius 0.35s"] |
| 1032 | + [:<> |
| 1033 | + [s/div |
| 1034 | + {:style |
| 1035 | + (merge |
| 1036 | + {:position :absolute |
| 1037 | + :pointer-events :none |
| 1038 | + :top -1 |
| 1039 | + :left -1 |
| 1040 | + :right -1 |
| 1041 | + :bottom -1 |
| 1042 | + :transition transition} |
| 1043 | + (when (and selected (not hover)) |
| 1044 | + {:box-shadow [0 0 3 color]}) |
| 1045 | + (cond |
| 1046 | + (and selected hover) |
| 1047 | + {:border-top-right-radius (:border-radius theme) |
| 1048 | + :border-bottom-right-radius (:border-radius theme) |
| 1049 | + :border [1 :solid color]} |
| 1050 | + selected |
| 1051 | + {:border-radius (:border-radius theme) |
| 1052 | + :border [1 :solid color]} |
| 1053 | + :else |
| 1054 | + {:border-radius (:border-radius theme) |
| 1055 | + :border [1 :solid "rgba(0,0,0,0)"]}))}] |
| 1056 | + [s/div |
| 1057 | + {:style |
| 1058 | + (merge |
| 1059 | + {:position :absolute |
| 1060 | + :pointer-events :none |
| 1061 | + :z-index 2 |
| 1062 | + :left (- (dec (:padding theme))) |
| 1063 | + :top 0 |
| 1064 | + :bottom 0 |
| 1065 | + :border-radius (:border-radius theme) |
| 1066 | + :transition transition} |
| 1067 | + (when selected |
| 1068 | + {:right -1 |
| 1069 | + :top -1 |
| 1070 | + :bottom -1}) |
| 1071 | + (when-not selected |
| 1072 | + {:opacity 0.85}) |
| 1073 | + (when (and selected hover) |
| 1074 | + {:box-shadow [0 0 3 (get theme (nth theme/order (:depth context)))]}) |
| 1075 | + (if-not hover |
| 1076 | + {:border-left [(- (:padding theme) 1) :solid "rgba(0,0,0,0)"]} |
| 1077 | + {:border-left [(- (:padding theme) 1) :solid color]}))}]])) |
1025 | 1078 |
|
1026 | 1079 | (defn wrapper [context & children]
|
1027 | 1080 | (let [theme (theme/use-theme)
|
1028 | 1081 | {:keys [ref value selected]} (use-options)
|
1029 |
| - wrapper-options (use-wrapper-options context)] |
| 1082 | + wrapper-options (use-wrapper-options context) |
| 1083 | + background (get-background context)] |
1030 | 1084 | (into
|
1031 | 1085 | [s/div
|
1032 | 1086 | (merge
|
|
1042 | 1096 | :z-index 0
|
1043 | 1097 | :flex "1"
|
1044 | 1098 | :font-family (:font-family theme)
|
1045 |
| - :border-radius (:border-radius theme) |
1046 |
| - :border (if selected |
1047 |
| - [1 :solid (get theme (nth theme/order selected))] |
1048 |
| - [1 :solid "rgba(0,0,0,0)"]) |
1049 |
| - :box-shadow (when selected [0 0 3 (get theme (nth theme/order selected))]) |
1050 |
| - :background (let [bg (get-background context)] |
1051 |
| - (when selected bg))}}) |
1052 |
| - [hover-border context]] |
| 1099 | + :border [1 :solid "rgba(0,0,0,0)"] |
| 1100 | + :background (when selected background)}}) |
| 1101 | + [inspector-border context] |
| 1102 | + [multi-select-counter context]] |
1053 | 1103 | children)))
|
1054 | 1104 |
|
1055 | 1105 | (defn- inspector* [context value]
|
|
0 commit comments