@ohos-ports/instructure-ui-breadcrumb 11.7.5-beta.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 +1330 -0
- package/LICENSE.md +28 -0
- package/README.md +46 -0
- package/es/Breadcrumb/v1/BreadcrumbLink/index.js +119 -0
- package/es/Breadcrumb/v1/BreadcrumbLink/props.js +26 -0
- package/es/Breadcrumb/v1/index.js +113 -0
- package/es/Breadcrumb/v1/props.js +26 -0
- package/es/Breadcrumb/v1/styles.js +106 -0
- package/es/Breadcrumb/v1/theme.js +49 -0
- package/es/Breadcrumb/v2/BreadcrumbLink/index.js +121 -0
- package/es/Breadcrumb/v2/BreadcrumbLink/props.js +26 -0
- package/es/Breadcrumb/v2/index.js +133 -0
- package/es/Breadcrumb/v2/props.js +26 -0
- package/es/Breadcrumb/v2/styles.js +77 -0
- package/es/exports/a.js +24 -0
- package/es/exports/b.js +24 -0
- package/lib/Breadcrumb/v1/BreadcrumbLink/index.js +125 -0
- package/lib/Breadcrumb/v1/BreadcrumbLink/props.js +31 -0
- package/lib/Breadcrumb/v1/index.js +125 -0
- package/lib/Breadcrumb/v1/props.js +31 -0
- package/lib/Breadcrumb/v1/styles.js +112 -0
- package/lib/Breadcrumb/v1/theme.js +55 -0
- package/lib/Breadcrumb/v2/BreadcrumbLink/index.js +127 -0
- package/lib/Breadcrumb/v2/BreadcrumbLink/props.js +31 -0
- package/lib/Breadcrumb/v2/index.js +145 -0
- package/lib/Breadcrumb/v2/props.js +31 -0
- package/lib/Breadcrumb/v2/styles.js +83 -0
- package/lib/exports/a.js +18 -0
- package/lib/exports/b.js +18 -0
- package/lib/package.json +1 -0
- package/package.json +90 -0
- package/scripts/fix-instructure-exports.js +137 -0
- package/src/Breadcrumb/v1/BreadcrumbLink/index.tsx +122 -0
- package/src/Breadcrumb/v1/BreadcrumbLink/props.ts +102 -0
- package/src/Breadcrumb/v1/README.md +141 -0
- package/src/Breadcrumb/v1/index.tsx +143 -0
- package/src/Breadcrumb/v1/props.ts +63 -0
- package/src/Breadcrumb/v1/styles.ts +116 -0
- package/src/Breadcrumb/v1/theme.ts +55 -0
- package/src/Breadcrumb/v2/BreadcrumbLink/index.tsx +123 -0
- package/src/Breadcrumb/v2/BreadcrumbLink/props.ts +101 -0
- package/src/Breadcrumb/v2/README.md +141 -0
- package/src/Breadcrumb/v2/index.tsx +157 -0
- package/src/Breadcrumb/v2/props.ts +64 -0
- package/src/Breadcrumb/v2/styles.ts +86 -0
- package/src/exports/a.ts +27 -0
- package/src/exports/b.ts +27 -0
- package/tsconfig.build.json +24 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +4 -0
- package/types/Breadcrumb/v1/BreadcrumbLink/index.d.ts +31 -0
- package/types/Breadcrumb/v1/BreadcrumbLink/index.d.ts.map +1 -0
- package/types/Breadcrumb/v1/BreadcrumbLink/props.d.ts +49 -0
- package/types/Breadcrumb/v1/BreadcrumbLink/props.d.ts.map +1 -0
- package/types/Breadcrumb/v1/index.d.ts +35 -0
- package/types/Breadcrumb/v1/index.d.ts.map +1 -0
- package/types/Breadcrumb/v1/props.d.ts +30 -0
- package/types/Breadcrumb/v1/props.d.ts.map +1 -0
- package/types/Breadcrumb/v1/styles.d.ts +15 -0
- package/types/Breadcrumb/v1/styles.d.ts.map +1 -0
- package/types/Breadcrumb/v1/theme.d.ts +10 -0
- package/types/Breadcrumb/v1/theme.d.ts.map +1 -0
- package/types/Breadcrumb/v2/BreadcrumbLink/index.d.ts +31 -0
- package/types/Breadcrumb/v2/BreadcrumbLink/index.d.ts.map +1 -0
- package/types/Breadcrumb/v2/BreadcrumbLink/props.d.ts +49 -0
- package/types/Breadcrumb/v2/BreadcrumbLink/props.d.ts.map +1 -0
- package/types/Breadcrumb/v2/index.d.ts +35 -0
- package/types/Breadcrumb/v2/index.d.ts.map +1 -0
- package/types/Breadcrumb/v2/props.d.ts +30 -0
- package/types/Breadcrumb/v2/props.d.ts.map +1 -0
- package/types/Breadcrumb/v2/styles.d.ts +14 -0
- package/types/Breadcrumb/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +4 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +4 -0
- package/types/exports/b.d.ts.map +1 -0
|
@@ -0,0 +1,143 @@
|
|
|
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 {
|
|
26
|
+
isValidElement,
|
|
27
|
+
cloneElement,
|
|
28
|
+
Children,
|
|
29
|
+
Component,
|
|
30
|
+
ReactElement
|
|
31
|
+
} from 'react'
|
|
32
|
+
|
|
33
|
+
import { View } from '@instructure/ui-view/v11_6'
|
|
34
|
+
|
|
35
|
+
import { withStyle } from '@instructure/emotion'
|
|
36
|
+
import { IconArrowOpenEndSolid } from '@instructure/ui-icons'
|
|
37
|
+
import { BreadcrumbLink } from './BreadcrumbLink/index.js'
|
|
38
|
+
|
|
39
|
+
import generateStyle from './styles.js'
|
|
40
|
+
import generateComponentTheme from './theme.js'
|
|
41
|
+
|
|
42
|
+
import { allowedProps } from './props.js'
|
|
43
|
+
import type { BreadcrumbProps } from './props'
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
---
|
|
47
|
+
category: components
|
|
48
|
+
---
|
|
49
|
+
**/
|
|
50
|
+
|
|
51
|
+
@withStyle(generateStyle, generateComponentTheme)
|
|
52
|
+
class Breadcrumb extends Component<BreadcrumbProps> {
|
|
53
|
+
static displayName = 'Breadcrumb'
|
|
54
|
+
static readonly componentId = 'Breadcrumb'
|
|
55
|
+
|
|
56
|
+
static allowedProps = allowedProps
|
|
57
|
+
static defaultProps = {
|
|
58
|
+
size: 'medium',
|
|
59
|
+
children: null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
ref: Element | null = null
|
|
63
|
+
|
|
64
|
+
handleRef = (el: Element | null) => {
|
|
65
|
+
this.ref = el
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
addAriaCurrent = (child: React.ReactNode) => {
|
|
69
|
+
const updatedChild = cloneElement(
|
|
70
|
+
child as React.ReactElement<{ 'aria-current'?: string }>,
|
|
71
|
+
{
|
|
72
|
+
'aria-current': 'page'
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
return updatedChild
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
componentDidMount() {
|
|
79
|
+
this.props.makeStyles?.()
|
|
80
|
+
}
|
|
81
|
+
componentDidUpdate() {
|
|
82
|
+
this.props.makeStyles?.()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static Link = BreadcrumbLink
|
|
86
|
+
|
|
87
|
+
renderChildren() {
|
|
88
|
+
const { styles, children } = this.props
|
|
89
|
+
const numChildren = Children.count(children)
|
|
90
|
+
const inlineStyle = {
|
|
91
|
+
maxWidth: `${Math.floor(100 / numChildren)}%`
|
|
92
|
+
}
|
|
93
|
+
let isAriaCurrentSet = false
|
|
94
|
+
|
|
95
|
+
return Children.map(children, (child, index) => {
|
|
96
|
+
const isLastElement = index === numChildren - 1
|
|
97
|
+
if (isValidElement(child)) {
|
|
98
|
+
const isCurrentPage =
|
|
99
|
+
(child as ReactElement<any>).props.isCurrentPage || false
|
|
100
|
+
if (isAriaCurrentSet && isCurrentPage) {
|
|
101
|
+
console.warn(
|
|
102
|
+
`Warning: Multiple elements with isCurrentPage=true found. Only one element should be set to current.`
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
if (isCurrentPage) {
|
|
106
|
+
isAriaCurrentSet = true
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return (
|
|
110
|
+
<li css={styles?.crumb} style={inlineStyle}>
|
|
111
|
+
{!isAriaCurrentSet &&
|
|
112
|
+
isLastElement &&
|
|
113
|
+
(child as React.ReactElement<any>).props.isCurrentPage !== false
|
|
114
|
+
? this.addAriaCurrent(child)
|
|
115
|
+
: child}
|
|
116
|
+
{index < numChildren - 1 && (
|
|
117
|
+
<IconArrowOpenEndSolid color="auto" css={styles?.separator} />
|
|
118
|
+
)}
|
|
119
|
+
</li>
|
|
120
|
+
)
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
render() {
|
|
125
|
+
const { styles } = this.props
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<View
|
|
129
|
+
role="navigation"
|
|
130
|
+
as="div"
|
|
131
|
+
margin={this.props.margin}
|
|
132
|
+
aria-label={this.props.label}
|
|
133
|
+
elementRef={this.handleRef}
|
|
134
|
+
data-cid="Breadcrumb"
|
|
135
|
+
>
|
|
136
|
+
<ol css={styles?.breadcrumb}>{this.renderChildren()}</ol>
|
|
137
|
+
</View>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export default Breadcrumb
|
|
143
|
+
export { Breadcrumb, BreadcrumbLink }
|
|
@@ -0,0 +1,63 @@
|
|
|
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 type {
|
|
25
|
+
Spacing,
|
|
26
|
+
WithStyleProps,
|
|
27
|
+
ComponentStyle
|
|
28
|
+
} from '@instructure/emotion'
|
|
29
|
+
import type { BreadcrumbTheme } from '@instructure/shared-types'
|
|
30
|
+
|
|
31
|
+
type BreadcrumbOwnProps = {
|
|
32
|
+
/**
|
|
33
|
+
* children of type Breadcrumb.Link
|
|
34
|
+
*/
|
|
35
|
+
children?: React.ReactNode // TODO: oneOf([BreadcrumbLink])
|
|
36
|
+
/**
|
|
37
|
+
* An accessible label for the navigation
|
|
38
|
+
*/
|
|
39
|
+
label: string
|
|
40
|
+
/**
|
|
41
|
+
* Sets the font-size of the breadcrumb text
|
|
42
|
+
*/
|
|
43
|
+
size?: 'small' | 'medium' | 'large'
|
|
44
|
+
/**
|
|
45
|
+
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
46
|
+
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
47
|
+
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
48
|
+
*/
|
|
49
|
+
margin?: Spacing
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type PropKeys = keyof BreadcrumbOwnProps
|
|
53
|
+
|
|
54
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
55
|
+
|
|
56
|
+
type BreadcrumbProps = BreadcrumbOwnProps &
|
|
57
|
+
WithStyleProps<BreadcrumbTheme, BreadcrumbStyle>
|
|
58
|
+
|
|
59
|
+
type BreadcrumbStyle = ComponentStyle<'breadcrumb' | 'crumb' | 'separator'>
|
|
60
|
+
const allowedProps: AllowedPropKeys = ['children', 'label', 'margin', 'size']
|
|
61
|
+
|
|
62
|
+
export type { BreadcrumbProps, BreadcrumbStyle }
|
|
63
|
+
export { allowedProps }
|
|
@@ -0,0 +1,116 @@
|
|
|
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 { BreadcrumbTheme } from '@instructure/shared-types'
|
|
26
|
+
import type { BreadcrumbProps, BreadcrumbStyle } 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: BreadcrumbTheme,
|
|
40
|
+
props: BreadcrumbProps
|
|
41
|
+
): BreadcrumbStyle => {
|
|
42
|
+
const { size } = props
|
|
43
|
+
|
|
44
|
+
const crumbSizeVariants = {
|
|
45
|
+
small: {
|
|
46
|
+
fontSize: componentTheme.smallFontSize,
|
|
47
|
+
paddingInlineEnd: `calc(${componentTheme.smallSeparatorFontSize} * 2)`,
|
|
48
|
+
paddingInlineStart: 0
|
|
49
|
+
},
|
|
50
|
+
medium: {
|
|
51
|
+
fontSize: componentTheme.mediumFontSize,
|
|
52
|
+
paddingInlineEnd: `calc(${componentTheme.mediumSeparatorFontSize} * 2)`,
|
|
53
|
+
paddingInlineStart: 0
|
|
54
|
+
},
|
|
55
|
+
large: {
|
|
56
|
+
fontSize: componentTheme.largeFontSize,
|
|
57
|
+
paddingInlineEnd: `calc(${componentTheme.largeSeparatorFontSize} * 2)`,
|
|
58
|
+
paddingInlineStart: 0
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const separatorSizeVariants = {
|
|
63
|
+
small: {
|
|
64
|
+
fontSize: componentTheme.smallSeparatorFontSize,
|
|
65
|
+
insetInlineEnd: `calc(${componentTheme.smallSeparatorFontSize} / 2)`,
|
|
66
|
+
insetInlineStart: 'auto',
|
|
67
|
+
marginTop: `calc(-1 * (${componentTheme.smallSeparatorFontSize} / 2))`
|
|
68
|
+
},
|
|
69
|
+
medium: {
|
|
70
|
+
fontSize: componentTheme.mediumSeparatorFontSize,
|
|
71
|
+
insetInlineEnd: `calc(${componentTheme.mediumSeparatorFontSize} / 2)`,
|
|
72
|
+
insetInlineStart: 'auto',
|
|
73
|
+
marginTop: `calc(-1 * (${componentTheme.mediumSeparatorFontSize} / 2))`
|
|
74
|
+
},
|
|
75
|
+
large: {
|
|
76
|
+
fontSize: componentTheme.largeSeparatorFontSize,
|
|
77
|
+
insetInlineEnd: `calc(${componentTheme.largeSeparatorFontSize} / 2)`,
|
|
78
|
+
insetInlineStart: 'auto',
|
|
79
|
+
marginTop: `calc(-1 * (${componentTheme.largeSeparatorFontSize} / 2))`
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
breadcrumb: {
|
|
85
|
+
label: 'breadcrumb',
|
|
86
|
+
fontFamily: componentTheme.fontFamily,
|
|
87
|
+
margin: 0,
|
|
88
|
+
padding: 0,
|
|
89
|
+
listStyleType: 'none',
|
|
90
|
+
overflow: 'visible',
|
|
91
|
+
display: 'flex',
|
|
92
|
+
alignItems: 'center'
|
|
93
|
+
},
|
|
94
|
+
crumb: {
|
|
95
|
+
label: 'breadcrumb__crumb',
|
|
96
|
+
boxSizing: 'border-box',
|
|
97
|
+
position: 'relative',
|
|
98
|
+
...crumbSizeVariants[size!],
|
|
99
|
+
|
|
100
|
+
'&:last-child': {
|
|
101
|
+
paddingInlineEnd: 0
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
separator: {
|
|
105
|
+
label: 'breadcrumb__separator',
|
|
106
|
+
|
|
107
|
+
boxSizing: 'border-box',
|
|
108
|
+
position: 'absolute',
|
|
109
|
+
top: '50%',
|
|
110
|
+
color: componentTheme.separatorColor,
|
|
111
|
+
...separatorSizeVariants[size!]
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export default generateStyle
|
|
@@ -0,0 +1,55 @@
|
|
|
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 } from '@instructure/ui-themes'
|
|
26
|
+
import { BreadcrumbTheme } 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): BreadcrumbTheme => {
|
|
34
|
+
const { colors, typography } = theme
|
|
35
|
+
|
|
36
|
+
const componentVariables: BreadcrumbTheme = {
|
|
37
|
+
fontFamily: typography?.fontFamily,
|
|
38
|
+
separatorColor: colors?.contrasts?.grey4570,
|
|
39
|
+
|
|
40
|
+
smallSeparatorFontSize: '0.5rem',
|
|
41
|
+
smallFontSize: typography?.fontSizeSmall,
|
|
42
|
+
|
|
43
|
+
mediumSeparatorFontSize: '0.75rem',
|
|
44
|
+
mediumFontSize: typography?.fontSizeMedium,
|
|
45
|
+
|
|
46
|
+
largeSeparatorFontSize: '1rem',
|
|
47
|
+
largeFontSize: typography?.fontSizeLarge
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
...componentVariables
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default generateComponentTheme
|
|
@@ -0,0 +1,123 @@
|
|
|
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 { Component } from 'react'
|
|
26
|
+
|
|
27
|
+
import { TruncateText } from '@instructure/ui-truncate-text/latest'
|
|
28
|
+
import { Link } from '@instructure/ui-link/latest'
|
|
29
|
+
import { omitProps } from '@instructure/ui-react-utils'
|
|
30
|
+
import { Tooltip } from '@instructure/ui-tooltip/latest'
|
|
31
|
+
|
|
32
|
+
import { allowedProps } from './props.js'
|
|
33
|
+
import type { BreadcrumbLinkProps, BreadcrumbLinkState } from './props'
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
---
|
|
37
|
+
parent: Breadcrumb
|
|
38
|
+
id: Breadcrumb.Link
|
|
39
|
+
---
|
|
40
|
+
**/
|
|
41
|
+
|
|
42
|
+
class BreadcrumbLink extends Component<
|
|
43
|
+
BreadcrumbLinkProps,
|
|
44
|
+
BreadcrumbLinkState
|
|
45
|
+
> {
|
|
46
|
+
static displayName = 'BreadcrumbLink'
|
|
47
|
+
static readonly componentId = 'Breadcrumb.Link'
|
|
48
|
+
|
|
49
|
+
static allowedProps = allowedProps
|
|
50
|
+
static defaultProps = {}
|
|
51
|
+
|
|
52
|
+
ref: Element | null = null
|
|
53
|
+
|
|
54
|
+
handleRef = (el: Element | null) => {
|
|
55
|
+
this.ref = el
|
|
56
|
+
}
|
|
57
|
+
constructor(props: BreadcrumbLinkProps) {
|
|
58
|
+
super(props)
|
|
59
|
+
|
|
60
|
+
this.state = {
|
|
61
|
+
isTruncated: false
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
handleTruncation(isTruncated: boolean) {
|
|
65
|
+
if (isTruncated !== this.state.isTruncated) {
|
|
66
|
+
this.setState({ isTruncated })
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
render() {
|
|
71
|
+
const {
|
|
72
|
+
children,
|
|
73
|
+
href,
|
|
74
|
+
renderIcon,
|
|
75
|
+
iconPlacement,
|
|
76
|
+
onClick,
|
|
77
|
+
onMouseEnter,
|
|
78
|
+
isCurrentPage,
|
|
79
|
+
size
|
|
80
|
+
} = this.props
|
|
81
|
+
const { isTruncated } = this.state
|
|
82
|
+
const props = omitProps(this.props, BreadcrumbLink.allowedProps)
|
|
83
|
+
|
|
84
|
+
const isInteractive = onClick || href
|
|
85
|
+
return (
|
|
86
|
+
<Tooltip
|
|
87
|
+
renderTip={children}
|
|
88
|
+
preventTooltip={!isTruncated}
|
|
89
|
+
// this wraps the achor/button tag in a span and puts the aria-describedby on that instead of the anchor/button tag
|
|
90
|
+
// to avoid SRs reading the text twice when there is already an aria-label
|
|
91
|
+
{...(isInteractive && { as: 'span' })}
|
|
92
|
+
>
|
|
93
|
+
<Link
|
|
94
|
+
{...props}
|
|
95
|
+
href={href}
|
|
96
|
+
renderIcon={renderIcon}
|
|
97
|
+
iconPlacement={iconPlacement}
|
|
98
|
+
onClick={onClick}
|
|
99
|
+
onMouseEnter={onMouseEnter}
|
|
100
|
+
variant="standalone"
|
|
101
|
+
elementRef={this.handleRef}
|
|
102
|
+
forceButtonRole={false}
|
|
103
|
+
size={size}
|
|
104
|
+
{...(isCurrentPage && { 'aria-current': 'page' })}
|
|
105
|
+
{...(isTruncated && {
|
|
106
|
+
...(typeof children === 'string' && { 'aria-label': children }),
|
|
107
|
+
...(!isInteractive && { role: 'text' })
|
|
108
|
+
})}
|
|
109
|
+
data-cid="BreadcrumbLink"
|
|
110
|
+
>
|
|
111
|
+
<TruncateText
|
|
112
|
+
onUpdate={(isTruncated) => this.handleTruncation(isTruncated)}
|
|
113
|
+
>
|
|
114
|
+
<span aria-hidden={isTruncated}>{children}</span>
|
|
115
|
+
</TruncateText>
|
|
116
|
+
</Link>
|
|
117
|
+
</Tooltip>
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export default BreadcrumbLink
|
|
123
|
+
export { BreadcrumbLink }
|
|
@@ -0,0 +1,101 @@
|
|
|
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 React from 'react'
|
|
26
|
+
import type {
|
|
27
|
+
PickPropsWithExceptions,
|
|
28
|
+
OtherHTMLAttributes,
|
|
29
|
+
Renderable
|
|
30
|
+
} from '@instructure/shared-types'
|
|
31
|
+
import type { ViewOwnProps } from '@instructure/ui-view/latest'
|
|
32
|
+
import type { LinkProps } from '@instructure/ui-link/latest'
|
|
33
|
+
|
|
34
|
+
type BreadcrumbLinkOwnProps = {
|
|
35
|
+
/**
|
|
36
|
+
* Content to render as the crumb, generally should be text.
|
|
37
|
+
*/
|
|
38
|
+
children: React.ReactNode
|
|
39
|
+
/**
|
|
40
|
+
* Link the crumb should direct to; if an href is provided, the crumb will render as a link
|
|
41
|
+
*/
|
|
42
|
+
href?: string
|
|
43
|
+
/**
|
|
44
|
+
* If the Breadcrumb.Link has an onClick prop (and no href), it will render as a button
|
|
45
|
+
*/
|
|
46
|
+
onClick?: (event: React.MouseEvent<ViewOwnProps, MouseEvent>) => void
|
|
47
|
+
/**
|
|
48
|
+
* Fires when the Link is hovered
|
|
49
|
+
*/
|
|
50
|
+
onMouseEnter?: (event: React.MouseEvent<ViewOwnProps, MouseEvent>) => void
|
|
51
|
+
/**
|
|
52
|
+
* Sets the font-size of the breadcrumb text
|
|
53
|
+
*/
|
|
54
|
+
size?: 'small' | 'medium' | 'large'
|
|
55
|
+
/**
|
|
56
|
+
* Add an icon to the Breadcrumb.Link
|
|
57
|
+
*/
|
|
58
|
+
renderIcon?: Renderable
|
|
59
|
+
/**
|
|
60
|
+
* Place the icon before or after the text in the Breadcrumb.Link
|
|
61
|
+
*/
|
|
62
|
+
iconPlacement?: 'start' | 'end'
|
|
63
|
+
/**
|
|
64
|
+
* Whether the page this breadcrumb points to is the current one. If true, it sets aria-current="page".
|
|
65
|
+
* If this prop is not set to true on any breadcrumb element, the one recieving the aria-current="page" will always be the last element, unless the last element's isCurrentPage prop is explicity set to false.
|
|
66
|
+
*/
|
|
67
|
+
isCurrentPage?: boolean
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
type PropKeys = keyof BreadcrumbLinkOwnProps
|
|
71
|
+
|
|
72
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
73
|
+
|
|
74
|
+
type BreadcrumbLinkProps = PickPropsWithExceptions<
|
|
75
|
+
LinkProps,
|
|
76
|
+
| 'children'
|
|
77
|
+
| 'href'
|
|
78
|
+
| 'onClick'
|
|
79
|
+
| 'renderIcon'
|
|
80
|
+
| 'iconPlacement'
|
|
81
|
+
| 'elementRef'
|
|
82
|
+
> &
|
|
83
|
+
BreadcrumbLinkOwnProps &
|
|
84
|
+
OtherHTMLAttributes<BreadcrumbLinkOwnProps & LinkProps>
|
|
85
|
+
const allowedProps: AllowedPropKeys = [
|
|
86
|
+
'children',
|
|
87
|
+
'href',
|
|
88
|
+
'iconPlacement',
|
|
89
|
+
'onClick',
|
|
90
|
+
'onMouseEnter',
|
|
91
|
+
'renderIcon',
|
|
92
|
+
'size',
|
|
93
|
+
'isCurrentPage'
|
|
94
|
+
]
|
|
95
|
+
|
|
96
|
+
type BreadcrumbLinkState = {
|
|
97
|
+
isTruncated: boolean
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export type { BreadcrumbLinkProps, BreadcrumbLinkState }
|
|
101
|
+
export { allowedProps }
|