@symbo.ls/icon 2.11.451 → 2.11.453
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +67 -50
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import { isString, exec, replaceLiteralsWithObjectFields } from '@domql/utils'
|
|
4
4
|
|
|
5
|
+
const inheritFromIsActive = (el) => {
|
|
6
|
+
const { props } = el
|
|
7
|
+
const propsActive = props['.isActive']
|
|
8
|
+
return el.call('exec', propsActive.name || propsActive.icon)
|
|
9
|
+
}
|
|
10
|
+
|
|
5
11
|
const getIconName = (el, s) => {
|
|
6
12
|
const { key, props, deps } = el
|
|
7
|
-
let iconName = exec
|
|
13
|
+
let iconName = el.call('exec', props.name || props.icon || key, el)
|
|
8
14
|
|
|
9
15
|
if (isString(iconName) && iconName.includes('{{')) {
|
|
10
16
|
iconName = deps.replaceLiteralsWithObjectFields(iconName, s)
|
|
@@ -16,77 +22,55 @@ const getIconName = (el, s) => {
|
|
|
16
22
|
export const Icon = {
|
|
17
23
|
extend: 'Svg',
|
|
18
24
|
deps: { isString, replaceLiteralsWithObjectFields },
|
|
19
|
-
props: (el, s) => {
|
|
20
|
-
const { props, parent,
|
|
21
|
-
const { ICONS,
|
|
22
|
-
const { toCamelCase } =
|
|
25
|
+
props: (el, s, ctx) => {
|
|
26
|
+
const { props, parent, deps } = el
|
|
27
|
+
const { ICONS, useIconSprite, verbose } = ctx && ctx.designSystem
|
|
28
|
+
const { toCamelCase } = ctx && ctx.utils
|
|
23
29
|
|
|
24
|
-
|
|
30
|
+
const iconName = getIconName(el, s)
|
|
25
31
|
const camelCase = toCamelCase(iconName)
|
|
26
32
|
const isArray = camelCase.split(/([a-z])([A-Z])/g)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const semanticIcon = SEMANTIC_ICONS && SEMANTIC_ICONS[semanticIconRootName]
|
|
30
|
-
if (semanticIcon) {
|
|
31
|
-
const iconKey = iconName.includes('.') ? 'sfsymbols.' + iconName.split('.').slice(1).join('.') : 'sfsymbols'
|
|
32
|
-
iconName = semanticIcon[iconKey] || semanticIcon[iconName.split('.')[0].split(' ')[0]]
|
|
33
|
-
return {
|
|
34
|
-
tag: 'span',
|
|
35
|
-
semantic_symbols: true,
|
|
36
|
-
width: 'A',
|
|
37
|
-
height: 'A',
|
|
38
|
-
lineHeight: '1em',
|
|
39
|
-
':after': {
|
|
40
|
-
fontSize: 'Z',
|
|
41
|
-
fontWeight: '300',
|
|
42
|
-
content: `"${iconName}"`,
|
|
43
|
-
textAlign: 'center',
|
|
44
|
-
display: 'inline-block',
|
|
45
|
-
style: {
|
|
46
|
-
color: 'currentColor',
|
|
47
|
-
fontFamily: "'SF Pro Icons', 'SF Pro', 'SF Symbols', 'Segoe UI'"
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
33
|
+
const semanticIcon = getSemanticIcon(el, s, ctx)
|
|
34
|
+
if (semanticIcon) return semanticIcon
|
|
52
35
|
|
|
53
36
|
let activeIconName
|
|
54
|
-
if (props.isActive)
|
|
55
|
-
|
|
56
|
-
|
|
37
|
+
if (props.isActive) activeIconName = inheritFromIsActive(el)
|
|
38
|
+
const parentProps = parent.props
|
|
39
|
+
const parentPropsActive = parentProps['.isActive']
|
|
57
40
|
if (
|
|
58
41
|
parent &&
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
42
|
+
parentProps &&
|
|
43
|
+
parentProps.isActive &&
|
|
44
|
+
parentPropsActive &&
|
|
45
|
+
parentPropsActive.icon
|
|
63
46
|
) {
|
|
64
47
|
activeIconName = exec(
|
|
65
|
-
|
|
66
|
-
|
|
48
|
+
parentPropsActive.icon || parentPropsActive.Icon.name || parentPropsActive.Icon.icon,
|
|
49
|
+
el
|
|
50
|
+
)
|
|
67
51
|
}
|
|
68
52
|
|
|
69
53
|
if (isString(activeIconName) && activeIconName.includes('{{')) {
|
|
70
|
-
activeIconName = deps.replaceLiteralsWithObjectFields(activeIconName,
|
|
54
|
+
activeIconName = deps.replaceLiteralsWithObjectFields(activeIconName, s)
|
|
71
55
|
}
|
|
72
56
|
|
|
73
|
-
let
|
|
74
|
-
if (ICONS[activeIconName])
|
|
75
|
-
if (ICONS[camelCase])
|
|
76
|
-
else if (ICONS[isArray[0] + isArray[1]])
|
|
77
|
-
else if (ICONS[isArray[0]])
|
|
57
|
+
let iconInContext
|
|
58
|
+
if (ICONS[activeIconName]) iconInContext = activeIconName
|
|
59
|
+
if (ICONS[camelCase]) iconInContext = camelCase
|
|
60
|
+
else if (ICONS[isArray[0] + isArray[1]]) iconInContext = isArray[0] + isArray[1]
|
|
61
|
+
else if (ICONS[isArray[0]]) iconInContext = isArray[0]
|
|
78
62
|
else {
|
|
79
|
-
if (verbose)
|
|
63
|
+
if (verbose) el.warn('Can\'t find icon:', iconName, iconInContext)
|
|
80
64
|
}
|
|
81
65
|
|
|
82
|
-
const iconFromLibrary = ICONS[
|
|
66
|
+
const iconFromLibrary = ICONS[iconInContext]
|
|
83
67
|
const directSrc = (parent && parent.props && parent.props.src) || props.src
|
|
84
68
|
|
|
85
69
|
return {
|
|
86
70
|
width: 'A',
|
|
87
71
|
height: 'A',
|
|
88
72
|
display: 'inline-block',
|
|
89
|
-
spriteId: useIconSprite &&
|
|
73
|
+
spriteId: useIconSprite && iconInContext,
|
|
90
74
|
src: iconFromLibrary || directSrc || ICONS.noIcon,
|
|
91
75
|
style: { fill: 'currentColor', '*': { fill: 'currentColor' } }
|
|
92
76
|
}
|
|
@@ -103,7 +87,7 @@ export const IconText = {
|
|
|
103
87
|
},
|
|
104
88
|
|
|
105
89
|
Icon: {
|
|
106
|
-
props:
|
|
90
|
+
props: el => ({ icon: el.call('exec', el.parent.props.icon, el.parent) }),
|
|
107
91
|
if: ({ parent, props }) => {
|
|
108
92
|
return parent.props.icon || parent.props.Icon || props.name || props.icon || props.sfSymbols || parent.props.sfSymbols
|
|
109
93
|
}
|
|
@@ -134,3 +118,36 @@ export const FileIcon = {
|
|
|
134
118
|
icon: 'file'
|
|
135
119
|
}
|
|
136
120
|
}
|
|
121
|
+
|
|
122
|
+
const getSemanticIcon = (el, s, ctx) => {
|
|
123
|
+
const { SEMANTIC_ICONS } = ctx && ctx.designSystem
|
|
124
|
+
const { toCamelCase } = ctx && ctx.utils
|
|
125
|
+
|
|
126
|
+
let iconName = getIconName(el, s)
|
|
127
|
+
const camelCase = toCamelCase(iconName)
|
|
128
|
+
const isArray = camelCase.split(/([a-z])([A-Z])/g)
|
|
129
|
+
const semanticIconRootName = isArray[1] ? isArray[0] : iconName.split('.')[0].split(' ')[0]
|
|
130
|
+
const semanticIcon = SEMANTIC_ICONS && SEMANTIC_ICONS[semanticIconRootName]
|
|
131
|
+
if (semanticIcon) {
|
|
132
|
+
const iconKey = iconName.includes('.') ? 'sfsymbols.' + iconName.split('.').slice(1).join('.') : 'sfsymbols'
|
|
133
|
+
iconName = semanticIcon[iconKey] || semanticIcon[iconName.split('.')[0].split(' ')[0]]
|
|
134
|
+
return {
|
|
135
|
+
tag: 'span',
|
|
136
|
+
semantic_symbols: true,
|
|
137
|
+
width: 'A',
|
|
138
|
+
height: 'A',
|
|
139
|
+
lineHeight: '1em',
|
|
140
|
+
':after': {
|
|
141
|
+
fontSize: 'Z',
|
|
142
|
+
fontWeight: '300',
|
|
143
|
+
content: `"${iconName}"`,
|
|
144
|
+
textAlign: 'center',
|
|
145
|
+
display: 'inline-block',
|
|
146
|
+
style: {
|
|
147
|
+
color: 'currentColor',
|
|
148
|
+
fontFamily: "'SF Pro Icons', 'SF Pro', 'SF Symbols', 'Segoe UI'"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/icon",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.453",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"gitHead": "
|
|
6
|
+
"gitHead": "8e5458a957b9d2c75944023e2c31bab157034314",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@symbo.ls/atoms": "^2.11.
|
|
9
|
-
"@symbo.ls/utils": "^2.11.
|
|
8
|
+
"@symbo.ls/atoms": "^2.11.453",
|
|
9
|
+
"@symbo.ls/utils": "^2.11.453"
|
|
10
10
|
},
|
|
11
11
|
"source": "src/index.js"
|
|
12
12
|
}
|