@sb1/ffe-symbols-react 2.0.3 → 3.0.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,23 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.0.0](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-symbols-react@2.0.4...@sb1/ffe-symbols-react@3.0.0) (2023-11-03)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **ffe-symbols-react:** legg til typings for symbol ([2a93040](https://github.com/SpareBank1/designsystem/commit/2a93040d0091b434335ced7080f6914916647b78))
11
+
12
+ ### BREAKING CHANGES
13
+
14
+ - **ffe-symbols-react:** I forrige versjon som ble feilmarkert som minor.
15
+ Endringen innebærer at symbolnavn settes via ikon-prop og ikke children-prop.
16
+
17
+ ## [2.0.4](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-symbols-react@2.0.3...@sb1/ffe-symbols-react@2.0.4) (2023-11-02)
18
+
19
+ ### Bug Fixes
20
+
21
+ - **ffe-symbols-react:** oppdater symbol implementasjon ([6f2369d](https://github.com/SpareBank1/designsystem/commit/6f2369def69327cb981ae6b54ee6b503591c357a))
22
+
6
23
  ## [2.0.3](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-symbols-react@2.0.2...@sb1/ffe-symbols-react@2.0.3) (2023-10-02)
7
24
 
8
25
  ### Bug Fixes
package/es/Symbol.js CHANGED
@@ -1,4 +1,4 @@
1
- var _excluded = ["className", "children", "size", "weight", "fill", "ariaLabel"];
1
+ var _excluded = ["className", "size", "weight", "fill", "ariaLabel", "icon"];
2
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
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
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; }
@@ -7,18 +7,18 @@ import { string, bool, oneOf } from 'prop-types';
7
7
  import classNames from 'classnames';
8
8
  var _Symbol = function _Symbol(props) {
9
9
  var className = props.className,
10
- children = props.children,
11
10
  size = props.size,
12
11
  weight = props.weight,
13
12
  fill = props.fill,
14
13
  ariaLabel = props.ariaLabel,
14
+ icon = props.icon,
15
15
  rest = _objectWithoutProperties(props, _excluded);
16
16
  return /*#__PURE__*/React.createElement("span", _extends({
17
17
  className: classNames('ffe-symbol', fill ? "ffe-symbol--filled-".concat(weight) : "ffe-symbol--".concat(weight), size && "ffe-symbol--".concat(size), className),
18
18
  role: "graphics-symbol img",
19
19
  "aria-label": ariaLabel ? ariaLabel : null,
20
20
  "aria-hidden": !ariaLabel
21
- }, rest), children);
21
+ }, rest), icon);
22
22
  };
23
23
  export { _Symbol as Symbol };
24
24
  _Symbol.defaultProps = {
@@ -29,19 +29,14 @@ _Symbol.propTypes = {
29
29
  /** Fills the icon with color */
30
30
  fill: bool,
31
31
  /** The name of the icon that should be shown */
32
- children: string.isRequired,
32
+ icon: string.isRequired,
33
33
  /** Size of the icon, default is the closest defined font-size */
34
34
  size: oneOf(['xs', 'sm', 'md', 'lg', 'xl', '2xl']),
35
35
  /** Symbols stroke weight. This can affect overall size of symbol, 400 is default */
36
36
  weight: oneOf([300, 400, 500]),
37
37
  /** Additional classnames */
38
38
  className: string,
39
- /** Aria label text. If null, aria-hidden is automatically set to true */
40
- ariaLabel: function ariaLabel(props, propName, componentName) {
41
- var propValue = props[propName];
42
- if (propValue !== null && typeof propValue !== 'string') {
43
- return new Error("Invalid prop '".concat(propName, "' supplied to '").concat(componentName, "'. ") + "'".concat(propName, "' must be a string or null."));
44
- }
45
- }
39
+ /** Aria label text. If null/undefined, aria-hidden is automatically set to true */
40
+ ariaLabel: string
46
41
  };
47
42
  export default _Symbol;
package/lib/Symbol.js CHANGED
@@ -7,25 +7,25 @@ exports.default = exports.Symbol = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _propTypes = require("prop-types");
9
9
  var _classnames = _interopRequireDefault(require("classnames"));
10
- var _excluded = ["className", "children", "size", "weight", "fill", "ariaLabel"];
10
+ var _excluded = ["className", "size", "weight", "fill", "ariaLabel", "icon"];
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
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
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
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
15
  var _Symbol = exports.Symbol = function _Symbol(props) {
16
16
  var className = props.className,
17
- children = props.children,
18
17
  size = props.size,
19
18
  weight = props.weight,
20
19
  fill = props.fill,
21
20
  ariaLabel = props.ariaLabel,
21
+ icon = props.icon,
22
22
  rest = _objectWithoutProperties(props, _excluded);
23
23
  return /*#__PURE__*/_react.default.createElement("span", _extends({
24
24
  className: (0, _classnames.default)('ffe-symbol', fill ? "ffe-symbol--filled-".concat(weight) : "ffe-symbol--".concat(weight), size && "ffe-symbol--".concat(size), className),
25
25
  role: "graphics-symbol img",
26
26
  "aria-label": ariaLabel ? ariaLabel : null,
27
27
  "aria-hidden": !ariaLabel
28
- }, rest), children);
28
+ }, rest), icon);
29
29
  };
30
30
  _Symbol.defaultProps = {
31
31
  fill: false,
@@ -35,19 +35,14 @@ _Symbol.propTypes = {
35
35
  /** Fills the icon with color */
36
36
  fill: _propTypes.bool,
37
37
  /** The name of the icon that should be shown */
38
- children: _propTypes.string.isRequired,
38
+ icon: _propTypes.string.isRequired,
39
39
  /** Size of the icon, default is the closest defined font-size */
40
40
  size: (0, _propTypes.oneOf)(['xs', 'sm', 'md', 'lg', 'xl', '2xl']),
41
41
  /** Symbols stroke weight. This can affect overall size of symbol, 400 is default */
42
42
  weight: (0, _propTypes.oneOf)([300, 400, 500]),
43
43
  /** Additional classnames */
44
44
  className: _propTypes.string,
45
- /** Aria label text. If null, aria-hidden is automatically set to true */
46
- ariaLabel: function ariaLabel(props, propName, componentName) {
47
- var propValue = props[propName];
48
- if (propValue !== null && typeof propValue !== 'string') {
49
- return new Error("Invalid prop '".concat(propName, "' supplied to '").concat(componentName, "'. ") + "'".concat(propName, "' must be a string or null."));
50
- }
51
- }
45
+ /** Aria label text. If null/undefined, aria-hidden is automatically set to true */
46
+ ariaLabel: _propTypes.string
52
47
  };
53
48
  var _default = exports.default = _Symbol;
package/lib/index.js CHANGED
@@ -17,5 +17,5 @@ Object.defineProperty(exports, "default", {
17
17
  }
18
18
  });
19
19
  var _Symbol = _interopRequireWildcard(require("./Symbol"));
20
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
21
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sb1/ffe-symbols-react",
3
- "version": "2.0.3",
3
+ "version": "3.0.0",
4
4
  "description": "React-komponenter for Material Symbols tilpasset Sb1 sine behov",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -35,5 +35,5 @@
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "fcfb33cf5bc12d9253263e68dd59e2add55a79aa"
38
+ "gitHead": "1e12f8223e50e127b733fc99ef41a8b003bedafc"
39
39
  }
@@ -0,0 +1,18 @@
1
+ /* Fetches all the icon names by using the codepoints in the font */
2
+ const fetchSymbolNames = async () => {
3
+ let folderNames = [];
4
+ const url =
5
+ 'https://raw.githubusercontent.com/google/material-design-icons/master/variablefont/MaterialSymbolsRounded%5BFILL%2CGRAD%2Copsz%2Cwght%5D.codepoints';
6
+ const response = await fetch(url);
7
+ const data = await response.text();
8
+
9
+ const lines = data.split('\n');
10
+ const names = lines
11
+ .filter(line => line.trim() !== '')
12
+ .map(line => `'${line.split(' ')[0]}'`);
13
+ folderNames = [...folderNames, ...names];
14
+
15
+ return folderNames;
16
+ };
17
+
18
+ module.exports = fetchSymbolNames;
@@ -0,0 +1,29 @@
1
+ /*
2
+ This function is manually triggered, and will fetch all the names of the symbols.
3
+ The names are then gathered in an array that is used for typescript typings in the symbols component.
4
+
5
+ Important to only run this when we update the icon-font files, as we might sometimes be out of sync with whats
6
+ the latest in material icons.
7
+ */
8
+ const path = require('path');
9
+ const fs = require('fs').promises;
10
+ const fetchSymbolNames = require('./fetchSymbolNames');
11
+
12
+ const writeToFile = async (filePath, content) => {
13
+ try {
14
+ await fs.writeFile(filePath, content);
15
+ console.log('File written successfully');
16
+ } catch (error) {
17
+ console.error('Error writing file:', error);
18
+ }
19
+ };
20
+
21
+ const generateSymbolTypings = async () => {
22
+ const symbolNames = await fetchSymbolNames();
23
+ const fileContent = `export type SymbolName = ${symbolNames.join(' | ')}`;
24
+ const filePath = path.join(__dirname, '../src/typings/symbolNames.ts');
25
+
26
+ await writeToFile(filePath, fileContent);
27
+ };
28
+
29
+ generateSymbolTypings();
package/src/Symbol.js CHANGED
@@ -3,15 +3,7 @@ import { string, bool, oneOf } from 'prop-types';
3
3
  import classNames from 'classnames';
4
4
 
5
5
  export const Symbol = props => {
6
- const {
7
- className,
8
- children,
9
- size,
10
- weight,
11
- fill,
12
- ariaLabel,
13
- ...rest
14
- } = props;
6
+ const { className, size, weight, fill, ariaLabel, icon, ...rest } = props;
15
7
 
16
8
  return (
17
9
  <span
@@ -26,7 +18,7 @@ export const Symbol = props => {
26
18
  aria-hidden={!ariaLabel}
27
19
  {...rest}
28
20
  >
29
- {children}
21
+ {icon}
30
22
  </span>
31
23
  );
32
24
  };
@@ -40,24 +32,15 @@ Symbol.propTypes = {
40
32
  /** Fills the icon with color */
41
33
  fill: bool,
42
34
  /** The name of the icon that should be shown */
43
- children: string.isRequired,
35
+ icon: string.isRequired,
44
36
  /** Size of the icon, default is the closest defined font-size */
45
37
  size: oneOf(['xs', 'sm', 'md', 'lg', 'xl', '2xl']),
46
38
  /** Symbols stroke weight. This can affect overall size of symbol, 400 is default */
47
39
  weight: oneOf([300, 400, 500]),
48
40
  /** Additional classnames */
49
41
  className: string,
50
- /** Aria label text. If null, aria-hidden is automatically set to true */
51
- ariaLabel: function(props, propName, componentName) {
52
- const propValue = props[propName];
53
-
54
- if (propValue !== null && typeof propValue !== 'string') {
55
- return new Error(
56
- `Invalid prop '${propName}' supplied to '${componentName}'. ` +
57
- `'${propName}' must be a string or null.`,
58
- );
59
- }
60
- },
42
+ /** Aria label text. If null/undefined, aria-hidden is automatically set to true */
43
+ ariaLabel: string,
61
44
  };
62
45
 
63
46
  export default Symbol;
@@ -1,12 +1,7 @@
1
1
  import React from 'react';
2
2
  import Symbol from '.';
3
3
 
4
- const getWrapper = props =>
5
- shallow(
6
- <Symbol ariaLabel="hus icon" {...props}>
7
- home
8
- </Symbol>,
9
- );
4
+ const getWrapper = props => shallow(<Symbol icon="home" {...props} />);
10
5
 
11
6
  describe('<Symbol />', () => {
12
7
  it('renders without exploding', () => {
@@ -37,12 +32,12 @@ describe('<Symbol />', () => {
37
32
  const wrapper = getWrapper({ id: 'test-id' });
38
33
  expect(wrapper.prop('id')).toBe('test-id');
39
34
  });
40
- it('set aria-hidden to false when aria-label is set', () => {
35
+ it('set aria-hidden to true when aria-label is undefined', () => {
41
36
  const wrapper = getWrapper();
42
- expect(wrapper.prop('aria-hidden')).toBe(false);
43
- });
44
- it('set aria-hidden to true when aria-label is empty string', () => {
45
- const wrapper = getWrapper({ ariaLabel: '' });
46
37
  expect(wrapper.prop('aria-hidden')).toBe(true);
47
38
  });
39
+ it('set aria-hidden to false when aria-label is set', () => {
40
+ const wrapper = getWrapper({ ariaLabel: 'hus icon' });
41
+ expect(wrapper.prop('aria-hidden')).toBe(false);
42
+ });
48
43
  });
package/src/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import * as React from 'react';
2
+ import { SymbolName } from './typings/symbolNames.ts';
2
3
 
3
4
  export interface SymbolProps {
4
5
  fill?: boolean;
5
6
  size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
6
7
  weight?: 300 | 400 | 500;
7
- children: string;
8
+ icon: SymbolName;
8
9
  className?: string;
9
- ariaLabel: string | null;
10
+ ariaLabel?: string;
10
11
  }
11
12
 
12
13
  declare class Symbol extends React.Component<SymbolProps, any> {}