@symbo.ls/icon 1.1.5 → 1.2.0

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.
Files changed (2) hide show
  1. package/index.js +45 -9
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1,14 +1,50 @@
1
1
  'use strict'
2
2
 
3
- import style from './style'
4
-
5
- import { SVG } from '@symbo.ls/svg'
3
+ import { Flex, SVG } from '@symbo.ls/atoms'
6
4
 
7
5
  export const Icon = {
8
- extends: SVG,
9
- style,
10
- define: { name: param => param },
11
- name: ({ props }) => props.icon,
12
- attr: { viewBox: '0 0 24 24' },
13
- src: ({ key, name }) => name || key || 'noIcon'
6
+ extend: SVG,
7
+ props: ({ key, props, parent, context }) => {
8
+ const { ICONS } = context && context.system
9
+ const iconName = props.inheritedString || props.name || props.icon || key
10
+ const camelCase = toCamelCase(iconName)
11
+
12
+ const isArray = camelCase.split(/([a-z])([A-Z])/g)
13
+
14
+ let activeIconName
15
+ if (props.active) {
16
+ activeIconName = props['.active'].name || props['.active'].icon
17
+ }
18
+ if (parent.props.active && parent.props['.active'] && parent.props['.active'].icon) {
19
+ activeIconName = parent.props['.active'].icon.name || parent.props['.active'].icon.icon || parent.props['.active'].icon
20
+ }
21
+
22
+ const iconFromLibrary = ICONS[activeIconName] || ICONS[camelCase] || (ICONS[isArray[0] + isArray[1]]) || ICONS[isArray[0]] || ICONS['noIcon']
23
+
24
+ return {
25
+ width: 'A',
26
+ height: 'A',
27
+ display: 'inline-block',
28
+ src: iconFromLibrary,
29
+ style: { fill: 'currentColor' }
30
+ }
31
+ },
32
+ attr: { viewBox: '0 0 24 24' }
14
33
  }
34
+
35
+ export const IconText = {
36
+ extend: Flex,
37
+
38
+ props: {
39
+ align: 'center center',
40
+ lineHeight: 1
41
+ },
42
+
43
+ icon: {
44
+ extend: Icon,
45
+ if: ({ parent }) => parent.props.icon,
46
+ props: 'match'
47
+ },
48
+
49
+ text: ({ props }) => props.text
50
+ }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@symbo.ls/icon",
3
- "version": "1.1.5",
3
+ "version": "1.2.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
- "gitHead": "8590863dfd2c60cbe59db0b4bb8239c8a7585259",
6
+ "gitHead": "769d39aee2ab66f0d64b1e0052893442857e7432",
7
7
  "dependencies": {
8
8
  "@symbo.ls/svg": "latest"
9
9
  },