@sb1/ffe-symbols-react 1.1.1
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/CHANGELOG.md +17 -0
- package/LICENSE.md +21 -0
- package/README.md +25 -0
- package/es/Symbol.js +50 -0
- package/es/index.js +2 -0
- package/lib/Symbol.js +58 -0
- package/lib/index.js +10 -0
- package/package.json +36 -0
- package/src/Symbol.js +63 -0
- package/src/Symbol.spec.js +69 -0
- package/src/index.d.ts +9 -0
- package/src/index.js +3 -0
- package/types/index.d.ts +9 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [1.1.1](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-symbols-react@1.1.0...@sb1/ffe-symbols-react@1.1.1) (2023-08-16)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **ffe-symbols-react:** fix version number ([5979341](https://github.com/SpareBank1/designsystem/commit/5979341fb9aa3c2d58403025dfb03696c8e34d88))
|
|
11
|
+
- **ffe-symbols-react:** gjør npm pakke public og fjern grade variabel ([5d178b7](https://github.com/SpareBank1/designsystem/commit/5d178b7aedcd70724dad2301c259cdfa36c75d76))
|
|
12
|
+
|
|
13
|
+
# 1.1.0 (2023-08-15)
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
- **ffe-symbols-react:** legg til komponent for material symbols ([d5c50a6](https://github.com/SpareBank1/designsystem/commit/d5c50a60ee855394f1441ed7b649b459955a2641))
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 SpareBank 1
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @sb1/ffe-symbols-react
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm install --save @sb1/ffe-symbols-react
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
Full documentation on icon usage is available at https://design.sparebank1.no/komponenter/ikoner/.
|
|
12
|
+
|
|
13
|
+
## Development
|
|
14
|
+
|
|
15
|
+
To start a local development server, run the following from the designsystem root folder:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install
|
|
19
|
+
npm run build
|
|
20
|
+
npm start
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
A local instance of `component-overview` with live reloading will run at http://localhost:1234/.
|
|
24
|
+
|
|
25
|
+
Example implementations using the latest versions of all components are also available at https://sparebank1.github.io/designsystem.
|
package/es/Symbol.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
var _excluded = ["className", "children", "size", "weight", "fill", "color", "ariaLabel"];
|
|
2
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { string, bool, oneOf } from 'prop-types';
|
|
7
|
+
import classNames from 'classnames';
|
|
8
|
+
var _Symbol = function _Symbol(props) {
|
|
9
|
+
var className = props.className,
|
|
10
|
+
children = props.children,
|
|
11
|
+
size = props.size,
|
|
12
|
+
weight = props.weight,
|
|
13
|
+
fill = props.fill,
|
|
14
|
+
color = props.color,
|
|
15
|
+
ariaLabel = props.ariaLabel,
|
|
16
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
17
|
+
return /*#__PURE__*/React.createElement("span", _extends({
|
|
18
|
+
className: classNames('ffe-symbol', "ffe-symbol--".concat(size), className),
|
|
19
|
+
role: "img",
|
|
20
|
+
style: {
|
|
21
|
+
fontVariationSettings: "'FILL' ".concat(fill ? 1 : 0, ", 'GRAD' 0, 'wght' ").concat(weight),
|
|
22
|
+
color: "var(--".concat(color, ")")
|
|
23
|
+
},
|
|
24
|
+
"aria-label": ariaLabel ? ariaLabel : null,
|
|
25
|
+
"aria-hidden": ariaLabel ? false : true
|
|
26
|
+
}, rest), children);
|
|
27
|
+
};
|
|
28
|
+
_Symbol.defaultProps = {
|
|
29
|
+
fill: false,
|
|
30
|
+
size: 'md',
|
|
31
|
+
weight: 400,
|
|
32
|
+
color: 'ffe-v-symbol-default-color'
|
|
33
|
+
};
|
|
34
|
+
_Symbol.propTypes = {
|
|
35
|
+
/** Fills the icon with color */
|
|
36
|
+
fill: bool,
|
|
37
|
+
/** The name of the icon that should be shown */
|
|
38
|
+
children: string.isRequired,
|
|
39
|
+
/** Size of the icon, medium is default */
|
|
40
|
+
size: oneOf(['xs', 'sm', 'md', 'lg', 'xl', '2xl']),
|
|
41
|
+
/** Symbols stroke weight. This can affect overall size of symbol, 400 is default */
|
|
42
|
+
weight: oneOf([300, 400, 500, 600]),
|
|
43
|
+
/** Color of the symbol, value should be name of FFE color variable example: ffe-farge-vann */
|
|
44
|
+
color: string,
|
|
45
|
+
/** Additional classnames */
|
|
46
|
+
className: string,
|
|
47
|
+
/** Aria label text. If empty aria-hidden is automatically set to true */
|
|
48
|
+
ariaLabel: string.isRequired
|
|
49
|
+
};
|
|
50
|
+
export default _Symbol;
|
package/es/index.js
ADDED
package/lib/Symbol.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _propTypes = require("prop-types");
|
|
9
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
|
+
var _excluded = ["className", "children", "size", "weight", "fill", "color", "ariaLabel"];
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
13
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
14
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
15
|
+
var _Symbol = function _Symbol(props) {
|
|
16
|
+
var className = props.className,
|
|
17
|
+
children = props.children,
|
|
18
|
+
size = props.size,
|
|
19
|
+
weight = props.weight,
|
|
20
|
+
fill = props.fill,
|
|
21
|
+
color = props.color,
|
|
22
|
+
ariaLabel = props.ariaLabel,
|
|
23
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
24
|
+
return /*#__PURE__*/_react.default.createElement("span", _extends({
|
|
25
|
+
className: (0, _classnames.default)('ffe-symbol', "ffe-symbol--".concat(size), className),
|
|
26
|
+
role: "img",
|
|
27
|
+
style: {
|
|
28
|
+
fontVariationSettings: "'FILL' ".concat(fill ? 1 : 0, ", 'GRAD' 0, 'wght' ").concat(weight),
|
|
29
|
+
color: "var(--".concat(color, ")")
|
|
30
|
+
},
|
|
31
|
+
"aria-label": ariaLabel ? ariaLabel : null,
|
|
32
|
+
"aria-hidden": ariaLabel ? false : true
|
|
33
|
+
}, rest), children);
|
|
34
|
+
};
|
|
35
|
+
_Symbol.defaultProps = {
|
|
36
|
+
fill: false,
|
|
37
|
+
size: 'md',
|
|
38
|
+
weight: 400,
|
|
39
|
+
color: 'ffe-v-symbol-default-color'
|
|
40
|
+
};
|
|
41
|
+
_Symbol.propTypes = {
|
|
42
|
+
/** Fills the icon with color */
|
|
43
|
+
fill: _propTypes.bool,
|
|
44
|
+
/** The name of the icon that should be shown */
|
|
45
|
+
children: _propTypes.string.isRequired,
|
|
46
|
+
/** Size of the icon, medium is default */
|
|
47
|
+
size: (0, _propTypes.oneOf)(['xs', 'sm', 'md', 'lg', 'xl', '2xl']),
|
|
48
|
+
/** Symbols stroke weight. This can affect overall size of symbol, 400 is default */
|
|
49
|
+
weight: (0, _propTypes.oneOf)([300, 400, 500, 600]),
|
|
50
|
+
/** Color of the symbol, value should be name of FFE color variable example: ffe-farge-vann */
|
|
51
|
+
color: _propTypes.string,
|
|
52
|
+
/** Additional classnames */
|
|
53
|
+
className: _propTypes.string,
|
|
54
|
+
/** Aria label text. If empty aria-hidden is automatically set to true */
|
|
55
|
+
ariaLabel: _propTypes.string.isRequired
|
|
56
|
+
};
|
|
57
|
+
var _default = _Symbol;
|
|
58
|
+
exports.default = _default;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _Symbol2 = _interopRequireDefault(require("./Symbol"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
var _default = _Symbol2.default;
|
|
10
|
+
exports.default = _default;
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sb1/ffe-symbols-react",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "React-komponenter for Material Symbols tilpasset Sb1 sine behov",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "ffe-buildtool babel",
|
|
8
|
+
"watch": "ffe-buildtool babel-watch",
|
|
9
|
+
"lint": "eslint src",
|
|
10
|
+
"test": "ffe-buildtool jest",
|
|
11
|
+
"test:watch": "ffe-buildtool jest --watch"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "ssh://git@github.com:SpareBank1/designsystem.git"
|
|
16
|
+
},
|
|
17
|
+
"author": "SpareBank1",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/SpareBank1/designsystem/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/SpareBank1/designsystem#readme",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"classnames": "^2.3.2",
|
|
25
|
+
"prop-types": "^15.8.1",
|
|
26
|
+
"react": "^18.2.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@sb1/ffe-buildtool": "^0.5.0",
|
|
30
|
+
"eslint": "^5.9.0"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"gitHead": "b9fee6160c5c4b2a731a1bc3fe480a8bdfe6e838"
|
|
36
|
+
}
|
package/src/Symbol.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { string, bool, oneOf } from 'prop-types';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
|
|
5
|
+
const Symbol = props => {
|
|
6
|
+
const {
|
|
7
|
+
className,
|
|
8
|
+
children,
|
|
9
|
+
size,
|
|
10
|
+
weight,
|
|
11
|
+
fill,
|
|
12
|
+
color,
|
|
13
|
+
ariaLabel,
|
|
14
|
+
...rest
|
|
15
|
+
} = props;
|
|
16
|
+
return (
|
|
17
|
+
<span
|
|
18
|
+
className={classNames(
|
|
19
|
+
'ffe-symbol',
|
|
20
|
+
`ffe-symbol--${size}`,
|
|
21
|
+
className,
|
|
22
|
+
)}
|
|
23
|
+
role="img"
|
|
24
|
+
style={{
|
|
25
|
+
fontVariationSettings: `'FILL' ${
|
|
26
|
+
fill ? 1 : 0
|
|
27
|
+
}, 'GRAD' 0, 'wght' ${weight}`,
|
|
28
|
+
color: `var(--${color})`,
|
|
29
|
+
}}
|
|
30
|
+
aria-label={ariaLabel ? ariaLabel : null}
|
|
31
|
+
aria-hidden={ariaLabel ? false : true}
|
|
32
|
+
{...rest}
|
|
33
|
+
>
|
|
34
|
+
{children}
|
|
35
|
+
</span>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
Symbol.defaultProps = {
|
|
40
|
+
fill: false,
|
|
41
|
+
size: 'md',
|
|
42
|
+
weight: 400,
|
|
43
|
+
color: 'ffe-v-symbol-default-color',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
Symbol.propTypes = {
|
|
47
|
+
/** Fills the icon with color */
|
|
48
|
+
fill: bool,
|
|
49
|
+
/** The name of the icon that should be shown */
|
|
50
|
+
children: string.isRequired,
|
|
51
|
+
/** Size of the icon, medium is default */
|
|
52
|
+
size: oneOf(['xs', 'sm', 'md', 'lg', 'xl', '2xl']),
|
|
53
|
+
/** Symbols stroke weight. This can affect overall size of symbol, 400 is default */
|
|
54
|
+
weight: oneOf([300, 400, 500, 600]),
|
|
55
|
+
/** Color of the symbol, value should be name of FFE color variable example: ffe-farge-vann */
|
|
56
|
+
color: string,
|
|
57
|
+
/** Additional classnames */
|
|
58
|
+
className: string,
|
|
59
|
+
/** Aria label text. If empty aria-hidden is automatically set to true */
|
|
60
|
+
ariaLabel: string.isRequired,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default Symbol;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Symbol from '.';
|
|
3
|
+
|
|
4
|
+
const getWrapper = props =>
|
|
5
|
+
shallow(
|
|
6
|
+
<Symbol ariaLabel="hus icon" {...props}>
|
|
7
|
+
home
|
|
8
|
+
</Symbol>,
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
describe('<Symbol />', () => {
|
|
12
|
+
it('renders without exploding', () => {
|
|
13
|
+
const wrapper = getWrapper();
|
|
14
|
+
expect(wrapper.exists()).toBe(true);
|
|
15
|
+
expect(wrapper.is('span')).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
it('renders filled symbol correctly', () => {
|
|
18
|
+
const wrapper = getWrapper();
|
|
19
|
+
expect(wrapper.get(0).props.style).toHaveProperty(
|
|
20
|
+
'fontVariationSettings',
|
|
21
|
+
"'FILL' 0, 'GRAD' 0, 'wght' 400",
|
|
22
|
+
);
|
|
23
|
+
const filled = getWrapper({ fill: true });
|
|
24
|
+
expect(filled.get(0).props.style).toHaveProperty(
|
|
25
|
+
'fontVariationSettings',
|
|
26
|
+
"'FILL' 1, 'GRAD' 0, 'wght' 400",
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
it('set correct symbol weight', () => {
|
|
30
|
+
const wrapper = getWrapper();
|
|
31
|
+
expect(wrapper.get(0).props.style).toHaveProperty(
|
|
32
|
+
'fontVariationSettings',
|
|
33
|
+
"'FILL' 0, 'GRAD' 0, 'wght' 400",
|
|
34
|
+
);
|
|
35
|
+
const filled = getWrapper({ weight: 600 });
|
|
36
|
+
expect(filled.get(0).props.style).toHaveProperty(
|
|
37
|
+
'fontVariationSettings',
|
|
38
|
+
"'FILL' 0, 'GRAD' 0, 'wght' 600",
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
it('set correct color based of prop', () => {
|
|
42
|
+
const wrapper = getWrapper({ color: 'ffe-farge-fjell' });
|
|
43
|
+
expect(wrapper.get(0).props.style).toHaveProperty(
|
|
44
|
+
'color',
|
|
45
|
+
'var(--ffe-farge-fjell)',
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
it('renders classes correctly', () => {
|
|
49
|
+
const wrapper = getWrapper({ className: 'test-class' });
|
|
50
|
+
expect(wrapper.hasClass('ffe-symbol')).toBe(true);
|
|
51
|
+
expect(wrapper.hasClass('test-class')).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
it('renders correct sized symbol of prop', () => {
|
|
54
|
+
const wrapper = getWrapper({ size: 'xl' });
|
|
55
|
+
expect(wrapper.hasClass('ffe-symbol--xl')).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
it('passes props correctly', () => {
|
|
58
|
+
const wrapper = getWrapper({ id: 'test-id' });
|
|
59
|
+
expect(wrapper.prop('id')).toBe('test-id');
|
|
60
|
+
});
|
|
61
|
+
it('set aria-hidden to false when aria-label is set', () => {
|
|
62
|
+
const wrapper = getWrapper();
|
|
63
|
+
expect(wrapper.prop('aria-hidden')).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
it('set aria-hidden to true when aria-label is empty string', () => {
|
|
66
|
+
const wrapper = getWrapper({ ariaLabel: '' });
|
|
67
|
+
expect(wrapper.prop('aria-hidden')).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
});
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED