|
1 | 1 | (ns quo2.components.icon
|
2 | 2 | (:require [clojure.string :as string]
|
3 | 3 | [quo2.components.icons.icons :as icons]
|
| 4 | + [quo2.components.icons.svg :as icons.svg] |
4 | 5 | [quo2.foundations.colors :as colors]
|
5 | 6 | [react-native.core :as rn]))
|
6 | 7 |
|
| 8 | +(defn- valid-color? |
| 9 | + [color] |
| 10 | + (or (keyword? color) |
| 11 | + (and (string? color) |
| 12 | + (not (string/blank? color))))) |
| 13 | + |
7 | 14 | (defn memo-icon-fn
|
8 | 15 | ([icon-name] (memo-icon-fn icon-name nil))
|
9 | 16 | ([icon-name
|
10 |
| - {:keys [color container-style size |
11 |
| - accessibility-label no-color] |
| 17 | + {:keys [color color-2 no-color |
| 18 | + container-style size accessibility-label] |
12 | 19 | :or {accessibility-label :icon}}]
|
13 | 20 | (let [size (or size 20)]
|
14 | 21 | ^{:key icon-name}
|
15 |
| - [rn/image |
16 |
| - {:style |
17 |
| - (merge {:width size |
18 |
| - :height size} |
| 22 | + (if-let [svg-icon (icons.svg/get-icon icon-name size)] |
| 23 | + [svg-icon |
| 24 | + {:size size |
| 25 | + :color (when (valid-color? color) color) |
| 26 | + :color-2 (when (valid-color? color-2) color-2) |
| 27 | + :accessibility-label accessibility-label |
| 28 | + :style container-style}] |
| 29 | + [rn/image |
| 30 | + {:style |
| 31 | + (merge {:width size |
| 32 | + :height size} |
19 | 33 |
|
20 |
| - (when (not no-color) |
21 |
| - {:tint-color (if (and (string? color) (not (string/blank? color))) |
22 |
| - color |
23 |
| - (colors/theme-colors colors/neutral-100 colors/white))}) |
| 34 | + (when (not no-color) |
| 35 | + {:tint-color (if (and (string? color) (not (string/blank? color))) |
| 36 | + color |
| 37 | + (colors/theme-colors colors/neutral-100 colors/white))}) |
24 | 38 |
|
25 |
| - container-style) |
26 |
| - :accessibility-label accessibility-label |
27 |
| - :source (icons/icon-source (str (name icon-name) size))}]))) |
| 39 | + container-style) |
| 40 | + :accessibility-label accessibility-label |
| 41 | + :source (icons/icon-source (str (name icon-name) size))}])))) |
28 | 42 |
|
29 | 43 | (def icon (memoize memo-icon-fn))
|
0 commit comments