From f488e19cfb2c06a38211b6207e8ba982e1321dd0 Mon Sep 17 00:00:00 2001 From: Niclas Liimatainen Date: Mon, 21 Sep 2020 15:42:21 +0300 Subject: [PATCH 1/3] Fix issue with navigation component name mangling in production builds --- packages/react/src/common/types.ts | 7 +++++++ .../react/src/components/navigation/Navigation.tsx | 11 ++++++----- .../navigation-actions/NavigationActions.tsx | 1 + .../navigation/navigation-row/NavigationRow.tsx | 1 + .../navigation/navigation-search/NavigationSearch.tsx | 1 + .../navigation/navigation-user/NavigationUser.tsx | 1 + 6 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 packages/react/src/common/types.ts diff --git a/packages/react/src/common/types.ts b/packages/react/src/common/types.ts new file mode 100644 index 0000000000..51d71e7494 --- /dev/null +++ b/packages/react/src/common/types.ts @@ -0,0 +1,7 @@ +import React from 'react'; + +/** + * Extends the React FunctionComponent type with the componentName key + * + */ +export type FCWithName = React.FC & { componentName: string }; diff --git a/packages/react/src/components/navigation/Navigation.tsx b/packages/react/src/components/navigation/Navigation.tsx index cb86fbf8ff..b3f13b85e7 100644 --- a/packages/react/src/components/navigation/Navigation.tsx +++ b/packages/react/src/components/navigation/Navigation.tsx @@ -15,6 +15,7 @@ import { NavigationDropdown } from './navigation-dropdown/NavigationDropdown'; import { useMobile } from '../../hooks/useMobile'; import { IconCross, IconMenuHamburger } from '../../icons'; import { NavigationReducerAction, NavigationReducerState } from './Navigation.interface'; +import { FCWithName } from '../../common/types'; const MOBILE_MENU_TRANSITION: UseTransitionProps = { from: { transform: 'translate3d(0, -10%, 0)', opacity: 0.85 }, @@ -107,7 +108,7 @@ const rearrangeChildrenForMobile = (children: React.ReactElement[], authenticate // moves the component to the start of the array const moveComponentToTop = (name: string) => { - const index = rearrangedChildren.findIndex((item) => (item?.type as React.FC)?.name === name); + const index = rearrangedChildren.findIndex((item) => (item?.type as FCWithName)?.componentName === name); if (index > -1) { const component = rearrangedChildren.splice(index, 1)[0]; rearrangedChildren.splice(0, 0, component); @@ -205,18 +206,18 @@ export const Navigation = ({ const childrenAsArray = React.Children.toArray(children) as React.ReactElement[]; // children without the navigation row const childrenWithoutNavigation = childrenAsArray.filter( - (child) => (child.type as React.FC)?.name !== 'NavigationRow', + (child) => (child.type as FCWithName)?.componentName !== 'NavigationRow', ); // filter out the NavigationRow, so that it can be rendered correctly based on the 'navigationRowDisplay' value - const navigation = childrenAsArray.filter((child) => (child.type as React.FC)?.name === 'NavigationRow'); + const navigation = childrenAsArray.filter((child) => (child.type as FCWithName)?.componentName === 'NavigationRow'); // children that will be rendered in the mobile menu let menuChildren = null; if (isMobile) { // navigation actions - const actions = childrenAsArray.find((child) => (child.type as React.FC).name === 'NavigationActions')?.props - ?.children; + const actions = childrenAsArray.find((child) => (child.type as FCWithName).componentName === 'NavigationActions') + ?.props?.children; const items = React.Children.toArray([navigation, actions]) as React.ReactElement[]; // rearrange children diff --git a/packages/react/src/components/navigation/navigation-actions/NavigationActions.tsx b/packages/react/src/components/navigation/navigation-actions/NavigationActions.tsx index 82342637c8..929809599a 100644 --- a/packages/react/src/components/navigation/navigation-actions/NavigationActions.tsx +++ b/packages/react/src/components/navigation/navigation-actions/NavigationActions.tsx @@ -5,3 +5,4 @@ import styles from './NavigationActions.module.css'; export const NavigationActions = ({ children }: React.PropsWithChildren<{}>) => (
{children}
); +NavigationActions.componentName = 'NavigationActions'; diff --git a/packages/react/src/components/navigation/navigation-row/NavigationRow.tsx b/packages/react/src/components/navigation/navigation-row/NavigationRow.tsx index 3a91430914..845cbb630a 100644 --- a/packages/react/src/components/navigation/navigation-row/NavigationRow.tsx +++ b/packages/react/src/components/navigation/navigation-row/NavigationRow.tsx @@ -37,3 +37,4 @@ export const NavigationRow = ({ display = 'subNav', children }: NavigationRowPro ); }; +NavigationRow.componentName = 'NavigationRow'; diff --git a/packages/react/src/components/navigation/navigation-search/NavigationSearch.tsx b/packages/react/src/components/navigation/navigation-search/NavigationSearch.tsx index c565a22707..a177222eb8 100644 --- a/packages/react/src/components/navigation/navigation-search/NavigationSearch.tsx +++ b/packages/react/src/components/navigation/navigation-search/NavigationSearch.tsx @@ -107,3 +107,4 @@ export const NavigationSearch = ({ ); }; +NavigationSearch.displayName = 'NavigationSearch'; diff --git a/packages/react/src/components/navigation/navigation-user/NavigationUser.tsx b/packages/react/src/components/navigation/navigation-user/NavigationUser.tsx index f534b8a309..eeb1618d2c 100644 --- a/packages/react/src/components/navigation/navigation-user/NavigationUser.tsx +++ b/packages/react/src/components/navigation/navigation-user/NavigationUser.tsx @@ -89,3 +89,4 @@ export const NavigationUser = ({ ); }; +NavigationUser.componentName = 'NavigationUser'; From 36161f352c7fb9019c4b750625fd59caa6ab0cc4 Mon Sep 17 00:00:00 2001 From: Niclas Liimatainen Date: Mon, 21 Sep 2020 15:50:25 +0300 Subject: [PATCH 2/3] Bump package versions and update changelog --- CHANGELOG.md | 20 ++++++++++++++++++++ packages/core/package.json | 4 ++-- packages/design-tokens/package.json | 2 +- packages/react/package.json | 4 ++-- site/package.json | 8 ++++---- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea958caa22..8137a2bb14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.13.2] - September 21, 2020 +### Documentation +#### Added +- Sketch file and symbol guidelines to the Contributing section +- Logo component documentation page +- HDS Colour contrast accessibility examples and guidelines +- Localisation guidelines + +#### Changed +- Improved styling of documentation site html elements to improve readability and visuals +- Search bar placeholder text +#### Removed +- Links to HDS Core Logo documentation (Logo is not implemented in HDS Core yet) + +### React +#### Fixed +- [Navigation] Fixed an issue where the component didn't work correctly in production builds. in ([#255](https://github.com/City-of-Helsinki/helsinki-design-system/pull/255)) + - The problem was caused by the navigation component names getting mangled in production builds. + + ## [0.13.1] - September 9, 2020 ### Documentation #### Added diff --git a/packages/core/package.json b/packages/core/package.json index ca91dbcd77..5795fab76f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "hds-core", - "version": "0.13.1", + "version": "0.13.2", "description": "Core styles for the Helsinki Design System", "author": "Anssi Lehtonen ", "contributors": [ @@ -29,7 +29,7 @@ "@storybook/html": "6.0.19", "copyfiles": "2.2.0", "cssnano": "4.1.10", - "hds-design-tokens": "0.13.1", + "hds-design-tokens": "0.13.2", "normalize.css": "8.0.1", "postcss": "7.0.30", "postcss-cli": "7.1.1", diff --git a/packages/design-tokens/package.json b/packages/design-tokens/package.json index b7de9ff25a..8a72901021 100644 --- a/packages/design-tokens/package.json +++ b/packages/design-tokens/package.json @@ -1,6 +1,6 @@ { "name": "hds-design-tokens", - "version": "0.13.1", + "version": "0.13.2", "description": "Design tokens for the Helsinki Design System", "author": "Niclas Liimatainen ", "homepage": "https://github.com/City-of-Helsinki/helsinki-design-system#readme", diff --git a/packages/react/package.json b/packages/react/package.json index 1eda65417b..82410a642c 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "hds-react", - "version": "0.13.1", + "version": "0.13.2", "license": "MIT", "main": "./index.js", "module": "./index.js", @@ -84,7 +84,7 @@ "@babel/runtime": "7.11.2", "@react-aria/visually-hidden": "3.2.0", "downshift": "5.4.0", - "hds-core": "0.13.1", + "hds-core": "0.13.2", "lodash.isequal": "4.5.0", "lodash.uniqueid": "4.0.1", "react-spring": "9.0.0-rc.3" diff --git a/site/package.json b/site/package.json index 1c37aec313..7b29a81590 100644 --- a/site/package.json +++ b/site/package.json @@ -1,6 +1,6 @@ { "name": "site", - "version": "0.13.1", + "version": "0.13.2", "private": true, "description": "Documentation for Helsinki Design System", "license": "MIT", @@ -22,9 +22,9 @@ "devDependencies": { "gatsby-cli": "2.12.29", "gatsby-plugin-matomo": "0.8.3", - "hds-core": "0.13.1", - "hds-design-tokens": "0.13.1", - "hds-react": "0.13.1", + "hds-core": "0.13.2", + "hds-design-tokens": "0.13.2", + "hds-react": "0.13.2", "react-helmet": "6.0.0", "rimraf": "3.0.2" } From 0495b3654a7f355d30ea338748550208f9429502 Mon Sep 17 00:00:00 2001 From: Niclas Liimatainen Date: Mon, 21 Sep 2020 15:53:00 +0300 Subject: [PATCH 3/3] Remove line --- packages/react/src/common/types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/react/src/common/types.ts b/packages/react/src/common/types.ts index 51d71e7494..c8cedf4095 100644 --- a/packages/react/src/common/types.ts +++ b/packages/react/src/common/types.ts @@ -2,6 +2,5 @@ import React from 'react'; /** * Extends the React FunctionComponent type with the componentName key - * */ export type FCWithName = React.FC & { componentName: string };