@newhighsco/chipset 6.12.3 → 6.13.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@newhighsco/chipset",
3
3
  "description": "Shareable, theme-able component library by New High Score",
4
- "version": "6.12.3",
4
+ "version": "6.13.3",
5
5
  "author": "New High Score <hello@newhighsco.re>",
6
6
  "license": "ISC",
7
7
  "config": {
@@ -25,9 +25,9 @@
25
25
  "url": "https://main--6004028a0df11e0021f58df8.chromatic.com"
26
26
  },
27
27
  "scripts": {
28
- "start": "start-storybook --static-dir .storybook/static --docs",
28
+ "start": "start-storybook --docs",
29
29
  "prebuild": "rm -rf build",
30
- "build": "build-storybook --output-dir build --static-dir .storybook/static --docs --quiet",
30
+ "build": "build-storybook --output-dir build --docs --quiet",
31
31
  "pretest": "yarn lint",
32
32
  "test": "npm-run-all --parallel test:*",
33
33
  "test:js": "jest --maxWorkers=2 --coverage",
@@ -47,40 +47,40 @@
47
47
  "react-device-detect": "2.1.2"
48
48
  },
49
49
  "devDependencies": {
50
- "@babel/core": "7.16.0",
50
+ "@babel/core": "7.16.7",
51
51
  "@babel/polyfill": "7.12.1",
52
- "@babel/preset-env": "7.16.0",
53
- "@babel/preset-react": "7.16.0",
54
- "@commitlint/cli": "14.1.0",
55
- "@fullhuman/postcss-purgecss": "4.0.3",
52
+ "@babel/preset-env": "7.16.7",
53
+ "@babel/preset-react": "7.16.7",
54
+ "@commitlint/cli": "16.0.2",
55
+ "@fullhuman/postcss-purgecss": "4.1.3",
56
56
  "@newhighsco/browserslist-config": "1.0.3",
57
- "@newhighsco/commitlint-config": "1.0.17",
57
+ "@newhighsco/commitlint-config": "1.0.20",
58
58
  "@newhighsco/editor-config": "1.1.2",
59
- "@newhighsco/eslint-config": "2.3.37",
60
- "@newhighsco/postcss-config": "3.4.15",
61
- "@newhighsco/prettier-config": "2.0.14",
62
- "@newhighsco/release-config": "1.0.76",
63
- "@newhighsco/storybook-preset": "4.3.26",
64
- "@newhighsco/stylelint-config": "3.0.3",
65
- "@storybook/react": "6.3.12",
66
- "@wojtekmaj/enzyme-adapter-react-17": "0.6.5",
67
- "babel-jest": "27.3.1",
59
+ "@newhighsco/eslint-config": "2.3.56",
60
+ "@newhighsco/postcss-config": "3.4.43",
61
+ "@newhighsco/prettier-config": "2.0.16",
62
+ "@newhighsco/release-config": "1.1.4",
63
+ "@newhighsco/storybook-preset": "4.4.12",
64
+ "@newhighsco/stylelint-config": "3.0.9",
65
+ "@storybook/react": "6.4.10",
66
+ "@wojtekmaj/enzyme-adapter-react-17": "0.6.6",
67
+ "babel-jest": "27.4.6",
68
68
  "babel-loader": "8.2.3",
69
- "chromatic": "6.0.5",
69
+ "chromatic": "6.3.4",
70
70
  "enzyme": "3.11.0",
71
- "eslint": "8.1.0",
71
+ "eslint": "8.6.0",
72
72
  "husky": "7.0.4",
73
73
  "identity-obj-proxy": "3.0.0",
74
- "jest": "27.3.1",
74
+ "jest": "27.4.7",
75
75
  "npm-run-all": "4.1.5",
76
- "postcss": "8.3.11",
77
- "prettier": "2.4.1",
76
+ "postcss": "8.4.5",
77
+ "prettier": "2.5.1",
78
78
  "react": "17.0.2",
79
79
  "react-dom": "17.0.2",
80
80
  "sass-true": "6.0.1",
81
- "semantic-release": "18.0.0",
82
- "stylelint": "14.0.1",
83
- "webpack": "5.61.0"
81
+ "semantic-release": "18.0.1",
82
+ "stylelint": "14.2.0",
83
+ "webpack": "5.65.0"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "react": "17.0.2",
@@ -1,6 +1,7 @@
1
- import React, { useState } from 'react'
1
+ import React from 'react'
2
2
  import { array, bool, func, shape, string } from 'prop-types'
3
3
  import classNames from 'classnames'
4
+ import { useToggle } from '../../hooks'
4
5
  import Button from '../Button'
5
6
  import Icon from '../Icon'
6
7
  import List from '../List'
@@ -22,10 +23,10 @@ const Navigation = ({
22
23
  }) => {
23
24
  if (!links.length) return null
24
25
 
25
- const [visible, setVisibility] = useState(!toggle)
26
+ const [visible, setVisibility] = useToggle(!toggle)
26
27
 
27
28
  const toggleVisibility = () => {
28
- setVisibility(!visible)
29
+ setVisibility()
29
30
  onToggle({ visible })
30
31
  }
31
32
 
@@ -0,0 +1,92 @@
1
+ import React from 'react'
2
+ import { bool, node, oneOf, shape, string } from 'prop-types'
3
+ import classNames from 'classnames'
4
+ import { useToggle } from '../../hooks'
5
+ import SmartLink from '../SmartLink'
6
+
7
+ /**
8
+ * Use `Tooltip` to present additional information about a specific element
9
+ */
10
+ const Tooltip = ({
11
+ hidden = true,
12
+ manual = true,
13
+ toggle,
14
+ href,
15
+ target,
16
+ heading,
17
+ children,
18
+ align = 'center',
19
+ valign = 'top',
20
+ disabled,
21
+ theme,
22
+ className
23
+ }) => {
24
+ if (!heading && !children) return null
25
+
26
+ const [visible, setVisibility] = useToggle(!hidden)
27
+
28
+ return (
29
+ <span
30
+ className={classNames(theme?.root, className)}
31
+ {...(!manual && {
32
+ onMouseOver: setVisibility,
33
+ onMouseOut: setVisibility,
34
+ onFocus: setVisibility,
35
+ onBlur: setVisibility,
36
+ onTouchEnd: setVisibility
37
+ })}
38
+ >
39
+ <SmartLink
40
+ className={classNames(theme?.toggle, visible && theme?.toggleActive)}
41
+ href={href}
42
+ target={target}
43
+ disabled={disabled}
44
+ aria-label="Toggle tooltip"
45
+ {...(manual && {
46
+ 'aria-expanded': visible,
47
+ onClick: setVisibility
48
+ })}
49
+ >
50
+ {toggle}
51
+ </SmartLink>
52
+ {(heading || children) && (
53
+ <span
54
+ className={classNames(
55
+ theme?.content,
56
+ align && theme?.[align],
57
+ valign && theme?.[valign]
58
+ )}
59
+ hidden={!visible}
60
+ >
61
+ {heading && <span className={theme?.heading}>{heading}</span>}
62
+ {children && <span className={theme?.copy}>{children}</span>}
63
+ </span>
64
+ )}
65
+ </span>
66
+ )
67
+ }
68
+
69
+ Tooltip.displayName = 'Tooltip'
70
+ Tooltip.propTypes = {
71
+ hidden: bool,
72
+ manual: bool,
73
+ toggle: node,
74
+ href: string,
75
+ target: string,
76
+ heading: node,
77
+ children: node,
78
+ align: oneOf(['left', 'right', 'center']),
79
+ valign: oneOf(['top', 'middle', 'bottom']),
80
+ disabled: bool,
81
+ theme: shape({
82
+ root: string,
83
+ toggle: string,
84
+ toggleActive: string,
85
+ content: string,
86
+ heading: string,
87
+ copy: string
88
+ }),
89
+ className: string
90
+ }
91
+
92
+ export default Tooltip
@@ -0,0 +1,68 @@
1
+ .root {
2
+ display: inline-block;
3
+ position: relative;
4
+ }
5
+
6
+ .toggle {
7
+ cursor: help;
8
+
9
+ &[href],
10
+ &[aria-expanded] {
11
+ cursor: pointer;
12
+ }
13
+ }
14
+
15
+ .content {
16
+ display: block;
17
+ position: absolute;
18
+ z-index: 1;
19
+
20
+ &[hidden] {
21
+ display: none;
22
+ }
23
+
24
+ &.top {
25
+ bottom: 100%;
26
+ }
27
+
28
+ &.bottom {
29
+ top: 100%;
30
+ }
31
+
32
+ &.left {
33
+ left: 0;
34
+ }
35
+
36
+ &.right {
37
+ right: 0;
38
+ }
39
+
40
+ &.center {
41
+ left: 50%;
42
+ transform: translateX(-50%);
43
+ }
44
+
45
+ &.middle {
46
+ top: 50%;
47
+ transform: translateY(-50%);
48
+
49
+ &.left {
50
+ left: auto;
51
+ right: 100%;
52
+ }
53
+
54
+ &.right {
55
+ left: 100%;
56
+ right: auto;
57
+ }
58
+
59
+ &.center {
60
+ transform: translate(-50%, -50%);
61
+ }
62
+ }
63
+ }
64
+
65
+ .heading,
66
+ .copy {
67
+ display: block;
68
+ }
@@ -0,0 +1,11 @@
1
+ import { withTheme } from '../../providers'
2
+ import PureTooltip from './Tooltip'
3
+
4
+ import theme from './Tooltip.module.scss'
5
+
6
+ const { displayName } = PureTooltip
7
+ const Tooltip = withTheme(displayName, theme)(PureTooltip)
8
+
9
+ Tooltip.displayName = displayName
10
+
11
+ export default Tooltip
@@ -18,4 +18,5 @@ export { default as Prose } from './Prose'
18
18
  export { default as ResponsiveMedia } from './ResponsiveMedia'
19
19
  export { default as SiteContainer } from './SiteContainer'
20
20
  export { default as SmartLink } from './SmartLink'
21
+ export { default as Tooltip } from './Tooltip'
21
22
  export { default as VisuallyHidden } from './VisuallyHidden'
@@ -0,0 +1 @@
1
+ export { useToggle } from './use-toggle'
@@ -0,0 +1,8 @@
1
+ import { useCallback, useState } from 'react'
2
+
3
+ export const useToggle = (initialState = false) => {
4
+ const [state, setState] = useState(initialState)
5
+ const toggle = useCallback(() => setState(state => !state), [])
6
+
7
+ return [state, toggle]
8
+ }
package/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './utils'
2
2
  export * from './components'
3
+ export * from './hooks'
3
4
  export * from './providers'