@instructure/ui-side-nav-bar 8.38.2-snapshot-11

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 (73) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +53 -0
  3. package/es/SideNavBar/SideNavBarItem/SideNavBarItemLocator.js +33 -0
  4. package/es/SideNavBar/SideNavBarItem/index.js +107 -0
  5. package/es/SideNavBar/SideNavBarItem/locator.js +26 -0
  6. package/es/SideNavBar/SideNavBarItem/props.js +36 -0
  7. package/es/SideNavBar/SideNavBarItem/styles.js +93 -0
  8. package/es/SideNavBar/SideNavBarItem/theme.js +73 -0
  9. package/es/SideNavBar/SideNavBarLocator.js +37 -0
  10. package/es/SideNavBar/index.js +130 -0
  11. package/es/SideNavBar/locator.js +27 -0
  12. package/es/SideNavBar/props.js +42 -0
  13. package/es/SideNavBar/styles.js +77 -0
  14. package/es/SideNavBar/theme.js +61 -0
  15. package/es/index.js +25 -0
  16. package/lib/SideNavBar/SideNavBarItem/SideNavBarItemLocator.js +41 -0
  17. package/lib/SideNavBar/SideNavBarItem/index.js +115 -0
  18. package/lib/SideNavBar/SideNavBarItem/locator.js +38 -0
  19. package/lib/SideNavBar/SideNavBarItem/props.js +45 -0
  20. package/lib/SideNavBar/SideNavBarItem/styles.js +100 -0
  21. package/lib/SideNavBar/SideNavBarItem/theme.js +80 -0
  22. package/lib/SideNavBar/SideNavBarLocator.js +49 -0
  23. package/lib/SideNavBar/index.js +147 -0
  24. package/lib/SideNavBar/locator.js +44 -0
  25. package/lib/SideNavBar/props.js +51 -0
  26. package/lib/SideNavBar/styles.js +84 -0
  27. package/lib/SideNavBar/theme.js +68 -0
  28. package/lib/index.js +18 -0
  29. package/lib/package.json +1 -0
  30. package/package.json +61 -0
  31. package/src/SideNavBar/README.md +74 -0
  32. package/src/SideNavBar/SideNavBarItem/SideNavBarItemLocator.ts +34 -0
  33. package/src/SideNavBar/SideNavBarItem/index.tsx +118 -0
  34. package/src/SideNavBar/SideNavBarItem/locator.ts +27 -0
  35. package/src/SideNavBar/SideNavBarItem/props.ts +102 -0
  36. package/src/SideNavBar/SideNavBarItem/styles.ts +103 -0
  37. package/src/SideNavBar/SideNavBarItem/theme.ts +82 -0
  38. package/src/SideNavBar/SideNavBarLocator.ts +40 -0
  39. package/src/SideNavBar/index.tsx +160 -0
  40. package/src/SideNavBar/locator.ts +29 -0
  41. package/src/SideNavBar/props.ts +118 -0
  42. package/src/SideNavBar/styles.ts +83 -0
  43. package/src/SideNavBar/theme.ts +66 -0
  44. package/src/index.ts +28 -0
  45. package/tsconfig.build.json +34 -0
  46. package/tsconfig.build.tsbuildinfo +1 -0
  47. package/tsconfig.json +4 -0
  48. package/types/SideNavBar/SideNavBarItem/SideNavBarItemLocator.d.ts +576 -0
  49. package/types/SideNavBar/SideNavBarItem/SideNavBarItemLocator.d.ts.map +1 -0
  50. package/types/SideNavBar/SideNavBarItem/index.d.ts +48 -0
  51. package/types/SideNavBar/SideNavBarItem/index.d.ts.map +1 -0
  52. package/types/SideNavBar/SideNavBarItem/locator.d.ts +4 -0
  53. package/types/SideNavBar/SideNavBarItem/locator.d.ts.map +1 -0
  54. package/types/SideNavBar/SideNavBarItem/props.d.ts +46 -0
  55. package/types/SideNavBar/SideNavBarItem/props.d.ts.map +1 -0
  56. package/types/SideNavBar/SideNavBarItem/styles.d.ts +15 -0
  57. package/types/SideNavBar/SideNavBarItem/styles.d.ts.map +1 -0
  58. package/types/SideNavBar/SideNavBarItem/theme.d.ts +10 -0
  59. package/types/SideNavBar/SideNavBarItem/theme.d.ts.map +1 -0
  60. package/types/SideNavBar/SideNavBarLocator.d.ts +1983 -0
  61. package/types/SideNavBar/SideNavBarLocator.d.ts.map +1 -0
  62. package/types/SideNavBar/index.d.ts +59 -0
  63. package/types/SideNavBar/index.d.ts.map +1 -0
  64. package/types/SideNavBar/locator.d.ts +5 -0
  65. package/types/SideNavBar/locator.d.ts.map +1 -0
  66. package/types/SideNavBar/props.d.ts +49 -0
  67. package/types/SideNavBar/props.d.ts.map +1 -0
  68. package/types/SideNavBar/styles.d.ts +15 -0
  69. package/types/SideNavBar/styles.d.ts.map +1 -0
  70. package/types/SideNavBar/theme.d.ts +10 -0
  71. package/types/SideNavBar/theme.d.ts.map +1 -0
  72. package/types/index.d.ts +4 -0
  73. package/types/index.d.ts.map +1 -0
@@ -0,0 +1,118 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ /** @jsx jsx */
25
+ import { Component } from 'react'
26
+
27
+ import { testable } from '@instructure/ui-testable'
28
+ import { omitProps, getElementType } from '@instructure/ui-react-utils'
29
+ import { Tooltip } from '@instructure/ui-tooltip'
30
+ import { hasVisibleChildren } from '@instructure/ui-a11y-utils'
31
+ import { withStyle, jsx } from '@instructure/emotion'
32
+
33
+ import generateStyle from './styles'
34
+ import generateComponentTheme from './theme'
35
+ import type { SideNavBarItemProps } from './props'
36
+ import { allowedProps, propTypes } from './props'
37
+
38
+ /**
39
+ ---
40
+ parent: SideNavBar
41
+ id: SideNavBar.Item
42
+ ---
43
+ @tsProps
44
+ **/
45
+ @withStyle(generateStyle, generateComponentTheme)
46
+ @testable()
47
+ class SideNavBarItem extends Component<SideNavBarItemProps> {
48
+ static readonly componentId = 'SideNavBar.Item'
49
+
50
+ static allowedProps = allowedProps
51
+ static propTypes = propTypes
52
+
53
+ static defaultProps = {
54
+ as: 'a',
55
+ selected: false,
56
+ minimized: false
57
+ } as const
58
+
59
+ ref: Element | null = null
60
+
61
+ handleRef = (el: Element | null) => {
62
+ const { elementRef } = this.props
63
+ this.ref = el
64
+ if (typeof elementRef === 'function') {
65
+ elementRef(el)
66
+ }
67
+ }
68
+
69
+ componentDidMount() {
70
+ this.props.makeStyles?.({ minimized: this.props.minimized })
71
+ }
72
+
73
+ componentDidUpdate() {
74
+ this.props.makeStyles?.({ minimized: this.props.minimized })
75
+ }
76
+
77
+ renderLink(addRef: boolean) {
78
+ const ElementType = getElementType(SideNavBarItem, this.props)
79
+
80
+ const { href, onClick, icon, label } = this.props
81
+
82
+ const props = omitProps(this.props, SideNavBarItem.allowedProps)
83
+
84
+ return (
85
+ <ElementType
86
+ {...props}
87
+ href={href}
88
+ onClick={onClick}
89
+ ref={addRef ? this.handleRef : undefined}
90
+ css={this.props.styles?.navigationItem}
91
+ aria-label={this.props.minimized ? (label as string) : undefined}
92
+ >
93
+ <div css={this.props.styles?.icon} aria-hidden="true">
94
+ {icon}
95
+ </div>
96
+ {!this.props.minimized ? (
97
+ <div css={this.props.styles?.label}>{label}</div>
98
+ ) : null}
99
+ </ElementType>
100
+ )
101
+ }
102
+
103
+ render() {
104
+ const { minimized, label } = this.props
105
+ const hasTooltip: boolean = minimized! && hasVisibleChildren(label)
106
+ const link = this.renderLink(!hasTooltip)
107
+ return hasTooltip ? (
108
+ <Tooltip renderTip={label} placement="end" elementRef={this.handleRef}>
109
+ {link}
110
+ </Tooltip>
111
+ ) : (
112
+ link
113
+ )
114
+ }
115
+ }
116
+
117
+ export default SideNavBarItem
118
+ export { SideNavBarItem }
@@ -0,0 +1,27 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ import { SideNavBarItemLocator } from './SideNavBarItemLocator'
25
+
26
+ export { SideNavBarItemLocator }
27
+ export default SideNavBarItemLocator
@@ -0,0 +1,102 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ import PropTypes from 'prop-types'
25
+ import React from 'react'
26
+ import type {
27
+ AsElementType,
28
+ PropValidators,
29
+ SideNavBarItemTheme,
30
+ OtherHTMLAttributes
31
+ } from '@instructure/shared-types'
32
+ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
33
+
34
+ type SideNavBarItemOwnProps = {
35
+ /**
36
+ * The reference to the underlying HTML element
37
+ */
38
+ elementRef?: (el: Element | null) => void
39
+ /**
40
+ * The visual to display (ex. an Image, Logo, Avatar, or Icon)
41
+ */
42
+ icon: React.ReactNode
43
+ /**
44
+ * The text to display for the SideNavBar Link
45
+ */
46
+ label: React.ReactNode
47
+ /**
48
+ * The element type to render as (will default to `<a>` if href is provided)
49
+ */
50
+ as?: AsElementType
51
+ /**
52
+ * If the SideNavBarItem goes to a new page, pass an href
53
+ */
54
+ href?: string
55
+ /**
56
+ * If the SideNavBarItem does not go to a new page pass an onClick
57
+ */
58
+ onClick?: (event: React.MouseEvent) => void
59
+ /**
60
+ * Denotes which SideNavBarItem is currently selected
61
+ */
62
+ selected?: boolean
63
+ /**
64
+ * When minimized is set to true, the `<SideNavBar />` shows icons only while the text becomes a tooltip. When it is set to false, the `<SideNavBar />` shows text in addition to the icons
65
+ */
66
+ minimized?: boolean
67
+ }
68
+
69
+ type PropKeys = keyof SideNavBarItemOwnProps
70
+
71
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
72
+
73
+ type SideNavBarItemProps = SideNavBarItemOwnProps &
74
+ WithStyleProps<SideNavBarItemTheme, SideNavBarItemStyle> &
75
+ OtherHTMLAttributes<SideNavBarItemOwnProps>
76
+
77
+ type SideNavBarItemStyle = ComponentStyle<'navigationItem' | 'icon' | 'label'>
78
+
79
+ const propTypes: PropValidators<PropKeys> = {
80
+ elementRef: PropTypes.func,
81
+ icon: PropTypes.node.isRequired,
82
+ label: PropTypes.node.isRequired,
83
+ as: PropTypes.elementType,
84
+ href: PropTypes.string,
85
+ onClick: PropTypes.func,
86
+ selected: PropTypes.bool,
87
+ minimized: PropTypes.bool
88
+ }
89
+
90
+ const allowedProps: AllowedPropKeys = [
91
+ 'elementRef',
92
+ 'icon',
93
+ 'label',
94
+ 'as',
95
+ 'href',
96
+ 'onClick',
97
+ 'selected',
98
+ 'minimized'
99
+ ]
100
+
101
+ export type { SideNavBarItemProps, SideNavBarItemStyle }
102
+ export { propTypes, allowedProps }
@@ -0,0 +1,103 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import type { SideNavBarItemTheme } from '@instructure/shared-types'
26
+ import type { SideNavBarItemProps, SideNavBarItemStyle } from './props'
27
+
28
+ /**
29
+ * ---
30
+ * private: true
31
+ * ---
32
+ * Generates the style object from the theme and provided additional information
33
+ * @param {Object} componentTheme The theme variable object.
34
+ * @param {Object} props the props of the component, the style is applied to
35
+ * @param {Object} state the state of the component, the style is applied to
36
+ * @return {Object} The final style object, which will be used in the component
37
+ */
38
+ const generateStyle = (
39
+ componentTheme: SideNavBarItemTheme,
40
+ props: SideNavBarItemProps
41
+ ): SideNavBarItemStyle => {
42
+ const { selected } = props
43
+
44
+ return {
45
+ navigationItem: {
46
+ label: 'navigationItem',
47
+ fontFamily: componentTheme.fontFamily,
48
+ fontWeight: componentTheme.fontWeight,
49
+ display: 'block',
50
+ width: '100%',
51
+ textAlign: 'center',
52
+ padding: componentTheme.contentPadding,
53
+ cursor: 'pointer',
54
+ border: 'none',
55
+ boxSizing: 'border-box',
56
+ textDecoration: componentTheme.linkTextDecoration,
57
+ overflowWrap: 'break-word',
58
+ wordWrap: 'break-word',
59
+ hyphens: 'auto',
60
+ ...(selected
61
+ ? {
62
+ backgroundColor: componentTheme.selectedBackgroundColor,
63
+ fill: componentTheme.selectedIconColor,
64
+ color: componentTheme.selectedFontColor,
65
+ '&:active, &:hover': {
66
+ backgroundColor: componentTheme.selectedBackgroundColor
67
+ },
68
+ '&:focus': {
69
+ backgroundColor: componentTheme.selectedBackgroundColor,
70
+ boxShadow: `${componentTheme.selectedOuterFocusOutline}, ${componentTheme.selectedInnerFocusOutline}`,
71
+ outline: 'none'
72
+ }
73
+ }
74
+ : {
75
+ backgroundColor: componentTheme.backgroundColor,
76
+ color: componentTheme.fontColor,
77
+ '&:active': {
78
+ backgroundColor: componentTheme.hoverBackgroundColor
79
+ },
80
+ '&:hover': {
81
+ backgroundColor: componentTheme.hoverBackgroundColor
82
+ },
83
+ '&:focus': {
84
+ backgroundColor: componentTheme.hoverBackgroundColor,
85
+ boxShadow: `${componentTheme.outerFocusOutline}, ${componentTheme.innerFocusOutline}`,
86
+ outline: 'none'
87
+ }
88
+ })
89
+ },
90
+ icon: {
91
+ label: 'navigationItem__icon',
92
+ fontSize: componentTheme.iconSize,
93
+ fill: componentTheme.iconColor
94
+ },
95
+ label: {
96
+ label: 'navigationItem__label',
97
+ fontSize: componentTheme.fontSize,
98
+ lineHeight: componentTheme.lineHeight
99
+ }
100
+ }
101
+ }
102
+
103
+ export default generateStyle
@@ -0,0 +1,82 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import type { Theme, ThemeSpecificStyle } from '@instructure/ui-themes'
26
+ import { SideNavBarItemTheme } from '@instructure/shared-types'
27
+
28
+ /**
29
+ * Generates the theme object for the component from the theme and provided additional information
30
+ * @param {Object} theme The actual theme object.
31
+ * @return {Object} The final theme object with the overrides and component variables
32
+ */
33
+ const generateComponentTheme = (theme: Theme): SideNavBarItemTheme => {
34
+ const { colors, spacing, typography, key: themeName } = theme
35
+
36
+ const themeSpecificStyle: ThemeSpecificStyle<SideNavBarItemTheme> = {
37
+ canvas: {
38
+ fontColor: theme['ic-brand-global-nav-menu-item__text-color'],
39
+ iconColor: theme['ic-brand-global-nav-ic-icon-svg-fill'],
40
+ backgroundColor: theme['ic-brand-global-nav-bgd'],
41
+ hoverBackgroundColor: theme['ic-global-nav-link-hover'],
42
+ selectedFontColor:
43
+ theme['ic-brand-global-nav-menu-item__text-color--active'],
44
+ selectedIconColor: theme['ic-brand-global-nav-ic-icon-svg-fill--active']
45
+ },
46
+ 'canvas-high-contrast': {
47
+ linkTextDecoration: 'underline'
48
+ }
49
+ }
50
+
51
+ const componentVariables: SideNavBarItemTheme = {
52
+ fontSize: typography?.fontSizeSmall,
53
+ fontFamily: typography?.fontFamily,
54
+ fontWeight: typography?.fontWeightLight,
55
+
56
+ fontColor: colors?.textLightest,
57
+ iconSize: '1.625rem',
58
+ iconColor: colors?.textLightest,
59
+ lineHeight: typography?.lineHeight,
60
+ backgroundColor: 'transparent',
61
+ linkTextDecoration: 'none',
62
+
63
+ hoverBackgroundColor: colors?.backgroundDarkest,
64
+ outerFocusOutline: `inset 0 0 0 0.125rem ${colors?.borderDarkest}`,
65
+ innerFocusOutline: `inset 0 0 0 0.25rem ${colors?.borderLightest}`,
66
+
67
+ selectedFontColor: colors?.textBrand,
68
+ selectedIconColor: colors?.textBrand,
69
+ selectedBackgroundColor: colors?.backgroundLightest,
70
+ selectedOuterFocusOutline: `inset 0 0 0 0.125rem ${colors?.borderLightest}`,
71
+ selectedInnerFocusOutline: `inset 0 0 0 0.25rem ${colors?.borderBrand}`,
72
+
73
+ contentPadding: spacing?.xxSmall
74
+ }
75
+
76
+ return {
77
+ ...componentVariables,
78
+ ...themeSpecificStyle[themeName]
79
+ }
80
+ }
81
+
82
+ export default generateComponentTheme
@@ -0,0 +1,40 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ import { locator } from '@instructure/ui-test-locator'
25
+
26
+ import { SideNavBar } from './index'
27
+ import { SideNavBarItemLocator } from './SideNavBarItem/SideNavBarItemLocator'
28
+
29
+ export { SideNavBarItemLocator }
30
+
31
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
32
+ export const SideNavBarLocator = locator(SideNavBar.selector, {
33
+ findAllItems: (...args: any[]) => {
34
+ return SideNavBarItemLocator.findAll(...args)
35
+ },
36
+
37
+ findItem: (...args: any[]) => {
38
+ return SideNavBarItemLocator.find(...args)
39
+ }
40
+ })
@@ -0,0 +1,160 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ /** @jsx jsx */
25
+ import React, { Component, Children, ReactElement } from 'react'
26
+
27
+ import { testable } from '@instructure/ui-testable'
28
+
29
+ import { omitProps, safeCloneElement } from '@instructure/ui-react-utils'
30
+ import { IconMoveStartLine } from '@instructure/ui-icons'
31
+ import { ScreenReaderContent } from '@instructure/ui-a11y-content'
32
+ import { withStyle, jsx } from '@instructure/emotion'
33
+
34
+ import { SideNavBarItem } from './SideNavBarItem'
35
+
36
+ import generateStyle from './styles'
37
+ import generateComponentTheme from './theme'
38
+ import type { SideNavBarProps, SideNavBarState } from './props'
39
+ import { allowedProps, propTypes } from './props'
40
+
41
+ const navMinimized = ({ minimized }: { minimized: boolean }) => ({
42
+ minimized: !minimized
43
+ })
44
+
45
+ /**
46
+ ---
47
+ category: components
48
+ ---
49
+ @tsProps
50
+ **/
51
+
52
+ @withStyle(generateStyle, generateComponentTheme)
53
+ @testable()
54
+ class SideNavBar extends Component<SideNavBarProps, SideNavBarState> {
55
+ static readonly componentId = 'SideNavBar'
56
+
57
+ static allowedProps = allowedProps
58
+ static propTypes = propTypes
59
+
60
+ static defaultProps = {
61
+ children: null,
62
+ defaultMinimized: false,
63
+ // TODO we should investigate later if it used or not
64
+ onClick: function (_e: React.MouseEvent) {}
65
+ }
66
+
67
+ static Item = SideNavBarItem
68
+
69
+ ref: Element | null = null
70
+
71
+ constructor(props: SideNavBarProps) {
72
+ super(props)
73
+
74
+ this.state = {
75
+ minimized: this.isControlled(props)
76
+ ? !!props.minimized
77
+ : !!props.defaultMinimized
78
+ }
79
+ }
80
+
81
+ componentDidMount() {
82
+ this.props.makeStyles?.({ minimized: this.minimized })
83
+ }
84
+
85
+ componentDidUpdate() {
86
+ this.props.makeStyles?.({ minimized: this.minimized })
87
+ }
88
+
89
+ get minimized() {
90
+ if (this.isControlled()) {
91
+ return !!this.props.minimized
92
+ }
93
+ return !!this.state.minimized
94
+ }
95
+
96
+ isControlled(props = this.props) {
97
+ return typeof props.minimized === 'boolean'
98
+ }
99
+
100
+ handleNavToggle = (event: React.SyntheticEvent) => {
101
+ if (!this.isControlled()) {
102
+ this.setState(navMinimized)
103
+ }
104
+ if (typeof this.props.onMinimized === 'function') {
105
+ this.props.onMinimized(event, !this.minimized)
106
+ }
107
+ }
108
+
109
+ renderChildren() {
110
+ return Children.map(this.props.children, (child) => {
111
+ const navItem = safeCloneElement(child as ReactElement, {
112
+ minimized: this.state.minimized
113
+ })
114
+ return <li css={this.props.styles?.list}>{navItem}</li>
115
+ })
116
+ }
117
+
118
+ toggleMessage() {
119
+ return this.state.minimized
120
+ ? this.props.toggleLabel.minimizedLabel
121
+ : this.props.toggleLabel.expandedLabel
122
+ }
123
+
124
+ render() {
125
+ const { label } = this.props
126
+
127
+ const props = omitProps(this.props, SideNavBar.allowedProps, ['minimized'])
128
+
129
+ return (
130
+ <nav
131
+ {...props}
132
+ css={this.props.styles?.navigation}
133
+ aria-label={label}
134
+ ref={(element) => {
135
+ this.ref = element
136
+ }}
137
+ >
138
+ <ul css={this.props.styles?.content}>{this.renderChildren()}</ul>
139
+ <div css={this.props.styles?.toggle}>
140
+ <SideNavBarItem
141
+ aria-expanded={!this.minimized}
142
+ onClick={this.handleNavToggle}
143
+ icon={
144
+ <IconMoveStartLine
145
+ css={this.props.styles?.toggleIcon}
146
+ inline={false}
147
+ />
148
+ }
149
+ label={
150
+ <ScreenReaderContent>{this.toggleMessage()}</ScreenReaderContent>
151
+ }
152
+ ></SideNavBarItem>
153
+ </div>
154
+ </nav>
155
+ )
156
+ }
157
+ }
158
+
159
+ export default SideNavBar
160
+ export { SideNavBar, SideNavBarItem }
@@ -0,0 +1,29 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ import { SideNavBarLocator } from './SideNavBarLocator'
25
+
26
+ export { SideNavBarItemLocator } from './SideNavBarLocator'
27
+
28
+ export { SideNavBarLocator }
29
+ export default SideNavBarLocator