@instructure/ui-billboard 11.6.0 → 11.6.1-snapshot-129
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 +33 -280
- package/es/Billboard/{index.js → v1/index.js} +3 -3
- package/es/Billboard/v2/index.js +188 -0
- package/es/Billboard/v2/props.js +26 -0
- package/es/Billboard/v2/styles.js +169 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -2
- package/lib/Billboard/{index.js → v1/index.js} +7 -7
- package/lib/Billboard/v2/index.js +195 -0
- package/lib/Billboard/v2/props.js +31 -0
- package/lib/Billboard/v2/styles.js +175 -0
- package/lib/{index.js → exports/a.js} +2 -2
- package/lib/exports/b.js +12 -0
- package/package.json +41 -19
- package/src/Billboard/{index.tsx → v1/index.tsx} +4 -4
- package/src/Billboard/{props.ts → v1/props.ts} +1 -1
- package/src/Billboard/v2/README.md +95 -0
- package/src/Billboard/v2/index.tsx +202 -0
- package/src/Billboard/v2/props.ts +128 -0
- package/src/Billboard/v2/styles.ts +158 -0
- package/src/exports/a.ts +25 -0
- package/src/exports/b.ts +25 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Billboard/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/Billboard/v1/index.d.ts.map +1 -0
- package/types/Billboard/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/Billboard/v1/props.d.ts.map +1 -0
- package/types/Billboard/v1/styles.d.ts.map +1 -0
- package/types/Billboard/v1/theme.d.ts.map +1 -0
- package/types/Billboard/v2/index.d.ts +58 -0
- package/types/Billboard/v2/index.d.ts.map +1 -0
- package/types/Billboard/v2/props.d.ts +74 -0
- package/types/Billboard/v2/props.d.ts.map +1 -0
- package/types/Billboard/v2/styles.d.ts +15 -0
- package/types/Billboard/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +3 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +3 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/Billboard/index.d.ts.map +0 -1
- package/types/Billboard/props.d.ts.map +0 -1
- package/types/Billboard/styles.d.ts.map +0 -1
- package/types/Billboard/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/es/Billboard/{props.js → v1/props.js} +0 -0
- /package/es/Billboard/{styles.js → v1/styles.js} +0 -0
- /package/es/Billboard/{theme.js → v1/theme.js} +0 -0
- /package/lib/Billboard/{props.js → v1/props.js} +0 -0
- /package/lib/Billboard/{styles.js → v1/styles.js} +0 -0
- /package/lib/Billboard/{theme.js → v1/theme.js} +0 -0
- /package/src/Billboard/{README.md → v1/README.md} +0 -0
- /package/src/Billboard/{styles.ts → v1/styles.ts} +0 -0
- /package/src/Billboard/{theme.ts → v1/theme.ts} +0 -0
- /package/types/Billboard/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Billboard/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
* copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
* SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* ---
|
|
33
|
+
* private: true
|
|
34
|
+
* ---
|
|
35
|
+
* Generates the style object from the theme and provided additional information
|
|
36
|
+
* @param {Object} componentTheme The theme variable object.
|
|
37
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
38
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
39
|
+
* @return {Object} The final style object, which will be used in the component
|
|
40
|
+
*/
|
|
41
|
+
const generateStyle = (componentTheme, props) => {
|
|
42
|
+
const size = props.size,
|
|
43
|
+
href = props.href,
|
|
44
|
+
onClick = props.onClick,
|
|
45
|
+
disabled = props.disabled,
|
|
46
|
+
hero = props.hero,
|
|
47
|
+
heading = props.heading;
|
|
48
|
+
const clickable = href || onClick;
|
|
49
|
+
const sizeVariants = {
|
|
50
|
+
small: {
|
|
51
|
+
billboard: {
|
|
52
|
+
padding: componentTheme.paddingSmall
|
|
53
|
+
},
|
|
54
|
+
hero: {
|
|
55
|
+
fontSize: '3rem'
|
|
56
|
+
},
|
|
57
|
+
message: {
|
|
58
|
+
fontSize: componentTheme.messageFontSizeSmall
|
|
59
|
+
},
|
|
60
|
+
heading: {
|
|
61
|
+
...(hero && {
|
|
62
|
+
margin: `${componentTheme.mediumMargin} 0 0`
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
medium: {
|
|
67
|
+
billboard: {
|
|
68
|
+
padding: componentTheme.paddingMedium
|
|
69
|
+
},
|
|
70
|
+
hero: {
|
|
71
|
+
fontSize: '5rem'
|
|
72
|
+
},
|
|
73
|
+
message: {
|
|
74
|
+
fontSize: componentTheme.messageFontSizeMedium
|
|
75
|
+
},
|
|
76
|
+
heading: {}
|
|
77
|
+
},
|
|
78
|
+
large: {
|
|
79
|
+
billboard: {
|
|
80
|
+
padding: componentTheme.paddingLarge
|
|
81
|
+
},
|
|
82
|
+
hero: {
|
|
83
|
+
fontSize: '10rem'
|
|
84
|
+
},
|
|
85
|
+
message: {
|
|
86
|
+
fontSize: componentTheme.messageFontSizeLarge
|
|
87
|
+
},
|
|
88
|
+
heading: {}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const clickableVariants = clickable ? {
|
|
92
|
+
appearance: 'none',
|
|
93
|
+
boxSizing: 'border-box',
|
|
94
|
+
cursor: 'pointer',
|
|
95
|
+
userSelect: 'none',
|
|
96
|
+
touchAction: 'manipulation',
|
|
97
|
+
width: '100%',
|
|
98
|
+
margin: '0',
|
|
99
|
+
border: `${componentTheme.buttonBorderWidth} ${componentTheme.buttonBorderStyle} transparent`,
|
|
100
|
+
borderRadius: componentTheme.buttonBorderRadius,
|
|
101
|
+
background: componentTheme.backgroundColor,
|
|
102
|
+
textDecoration: 'none',
|
|
103
|
+
'&:hover': {
|
|
104
|
+
borderStyle: componentTheme.buttonHoverBorderStyle
|
|
105
|
+
},
|
|
106
|
+
'&:hover, &:focus': {
|
|
107
|
+
textDecoration: 'none',
|
|
108
|
+
outline: 'none',
|
|
109
|
+
borderColor: componentTheme.messageColorClickable
|
|
110
|
+
},
|
|
111
|
+
'&:active': {
|
|
112
|
+
background: componentTheme.clickableActiveBg,
|
|
113
|
+
borderColor: componentTheme.messageColorClickable,
|
|
114
|
+
'& [class$=-billboard__hero], & [class$=-billboard__message]': {
|
|
115
|
+
color: componentTheme.clickableActiveText
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} : {
|
|
119
|
+
backgroundColor: componentTheme.backgroundColor
|
|
120
|
+
};
|
|
121
|
+
return {
|
|
122
|
+
billboard: {
|
|
123
|
+
label: 'billboard',
|
|
124
|
+
boxSizing: 'border-box',
|
|
125
|
+
position: 'relative',
|
|
126
|
+
fontFamily: componentTheme.fontFamily,
|
|
127
|
+
marginLeft: 'auto',
|
|
128
|
+
marginRight: 'auto',
|
|
129
|
+
textAlign: 'center',
|
|
130
|
+
display: 'block',
|
|
131
|
+
...sizeVariants[size].billboard,
|
|
132
|
+
...clickableVariants,
|
|
133
|
+
...(disabled && {
|
|
134
|
+
cursor: 'not-allowed',
|
|
135
|
+
pointerEvents: 'none',
|
|
136
|
+
opacity: 0.5
|
|
137
|
+
})
|
|
138
|
+
},
|
|
139
|
+
content: {
|
|
140
|
+
label: 'billboard__content',
|
|
141
|
+
display: 'block'
|
|
142
|
+
},
|
|
143
|
+
hero: {
|
|
144
|
+
label: 'billboard__hero',
|
|
145
|
+
display: 'block',
|
|
146
|
+
...sizeVariants[size].hero,
|
|
147
|
+
'& > img, & > svg': {
|
|
148
|
+
maxWidth: '100%',
|
|
149
|
+
display: 'block',
|
|
150
|
+
margin: '0 auto'
|
|
151
|
+
},
|
|
152
|
+
'& > img': {
|
|
153
|
+
height: 'auto'
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
heading: {
|
|
157
|
+
label: 'billboard__heading',
|
|
158
|
+
display: 'block',
|
|
159
|
+
...(hero && {
|
|
160
|
+
margin: `${componentTheme.largeMargin} 0 0`
|
|
161
|
+
}),
|
|
162
|
+
...sizeVariants[size].heading
|
|
163
|
+
},
|
|
164
|
+
message: {
|
|
165
|
+
label: 'billboard__message',
|
|
166
|
+
display: 'block',
|
|
167
|
+
color: clickable ? componentTheme.messageColorClickable : componentTheme.messageColor,
|
|
168
|
+
...((hero || heading) && {
|
|
169
|
+
margin: `${componentTheme.mediumMargin} 0 0`
|
|
170
|
+
}),
|
|
171
|
+
...sizeVariants[size].message
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
var _default = exports.default = generateStyle;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
Object.defineProperty(exports, "Billboard", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _v.Billboard;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
var
|
|
12
|
+
var _v = require("../Billboard/v1");
|
package/lib/exports/b.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-billboard",
|
|
3
|
-
"version": "11.6.
|
|
3
|
+
"version": "11.6.1-snapshot-129",
|
|
4
4
|
"description": "A UI component to display empty states, 404 pages, redirects, etc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -15,23 +15,23 @@
|
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@babel/runtime": "^7.27.6",
|
|
18
|
-
"@instructure/emotion": "11.6.
|
|
19
|
-
"@instructure/
|
|
20
|
-
"@instructure/
|
|
21
|
-
"@instructure/ui-img": "11.6.
|
|
22
|
-
"@instructure/ui-react-utils": "11.6.
|
|
23
|
-
"@instructure/ui-view": "11.6.
|
|
18
|
+
"@instructure/emotion": "11.6.1-snapshot-129",
|
|
19
|
+
"@instructure/shared-types": "11.6.1-snapshot-129",
|
|
20
|
+
"@instructure/ui-heading": "11.6.1-snapshot-129",
|
|
21
|
+
"@instructure/ui-img": "11.6.1-snapshot-129",
|
|
22
|
+
"@instructure/ui-react-utils": "11.6.1-snapshot-129",
|
|
23
|
+
"@instructure/ui-view": "11.6.1-snapshot-129"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@testing-library/jest-dom": "^6.6.3",
|
|
27
27
|
"@testing-library/react": "15.0.7",
|
|
28
28
|
"@testing-library/user-event": "^14.6.1",
|
|
29
29
|
"vitest": "^3.2.2",
|
|
30
|
-
"@instructure/ui-
|
|
31
|
-
"@instructure/ui-
|
|
32
|
-
"@instructure/ui-
|
|
33
|
-
"@instructure/ui-
|
|
34
|
-
"@instructure/ui-themes": "11.6.
|
|
30
|
+
"@instructure/ui-babel-preset": "11.6.1-snapshot-129",
|
|
31
|
+
"@instructure/ui-axe-check": "11.6.1-snapshot-129",
|
|
32
|
+
"@instructure/ui-icons": "11.6.1-snapshot-129",
|
|
33
|
+
"@instructure/ui-color-utils": "11.6.1-snapshot-129",
|
|
34
|
+
"@instructure/ui-themes": "11.6.1-snapshot-129"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"react": ">=18 <=19"
|
|
@@ -41,17 +41,39 @@
|
|
|
41
41
|
},
|
|
42
42
|
"sideEffects": false,
|
|
43
43
|
"exports": {
|
|
44
|
-
".": {
|
|
45
|
-
"types": "./types/index.d.ts",
|
|
46
|
-
"import": "./es/index.js",
|
|
47
|
-
"require": "./lib/index.js",
|
|
48
|
-
"default": "./es/index.js"
|
|
49
|
-
},
|
|
50
44
|
"./lib/*": "./lib/*",
|
|
51
45
|
"./es/*": "./es/*",
|
|
52
46
|
"./types/*": "./types/*",
|
|
53
47
|
"./package.json": "./package.json",
|
|
54
|
-
"./src/*": "./src/*"
|
|
48
|
+
"./src/*": "./src/*",
|
|
49
|
+
".": {
|
|
50
|
+
"src": "./src/exports/a.ts",
|
|
51
|
+
"types": "./types/exports/a.d.ts",
|
|
52
|
+
"import": "./es/exports/a.js",
|
|
53
|
+
"require": "./lib/exports/a.js",
|
|
54
|
+
"default": "./es/exports/a.js"
|
|
55
|
+
},
|
|
56
|
+
"./v11_6": {
|
|
57
|
+
"src": "./src/exports/a.ts",
|
|
58
|
+
"types": "./types/exports/a.d.ts",
|
|
59
|
+
"import": "./es/exports/a.js",
|
|
60
|
+
"require": "./lib/exports/a.js",
|
|
61
|
+
"default": "./es/exports/a.js"
|
|
62
|
+
},
|
|
63
|
+
"./v11_7": {
|
|
64
|
+
"src": "./src/exports/b.ts",
|
|
65
|
+
"types": "./types/exports/b.d.ts",
|
|
66
|
+
"import": "./es/exports/b.js",
|
|
67
|
+
"require": "./lib/exports/b.js",
|
|
68
|
+
"default": "./es/exports/b.js"
|
|
69
|
+
},
|
|
70
|
+
"./latest": {
|
|
71
|
+
"src": "./src/exports/b.ts",
|
|
72
|
+
"types": "./types/exports/b.d.ts",
|
|
73
|
+
"import": "./es/exports/b.js",
|
|
74
|
+
"require": "./lib/exports/b.js",
|
|
75
|
+
"default": "./es/exports/b.js"
|
|
76
|
+
}
|
|
55
77
|
},
|
|
56
78
|
"scripts": {
|
|
57
79
|
"lint": "ui-scripts lint",
|
|
@@ -24,22 +24,22 @@
|
|
|
24
24
|
|
|
25
25
|
import { Component, MouseEvent } from 'react'
|
|
26
26
|
|
|
27
|
-
import { Heading } from '@instructure/ui-heading'
|
|
28
|
-
import { View } from '@instructure/ui-view'
|
|
27
|
+
import { Heading } from '@instructure/ui-heading/v11_6'
|
|
28
|
+
import { View } from '@instructure/ui-view/v11_6'
|
|
29
29
|
import {
|
|
30
30
|
omitProps,
|
|
31
31
|
callRenderProp,
|
|
32
32
|
getElementType
|
|
33
33
|
} from '@instructure/ui-react-utils'
|
|
34
34
|
|
|
35
|
-
import { withStyle } from '@instructure/emotion'
|
|
35
|
+
import { withStyleLegacy as withStyle } from '@instructure/emotion'
|
|
36
36
|
|
|
37
37
|
import generateStyle from './styles'
|
|
38
38
|
import generateComponentTheme from './theme'
|
|
39
39
|
|
|
40
40
|
import { allowedProps } from './props'
|
|
41
41
|
import type { BillboardProps, HeroIconSize } from './props'
|
|
42
|
-
import type { ViewProps } from '@instructure/ui-view'
|
|
42
|
+
import type { ViewProps } from '@instructure/ui-view/v11_6'
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
---
|
|
@@ -32,7 +32,7 @@ import type {
|
|
|
32
32
|
BillboardTheme,
|
|
33
33
|
OtherHTMLAttributes
|
|
34
34
|
} from '@instructure/shared-types'
|
|
35
|
-
import type { ViewProps } from '@instructure/ui-view'
|
|
35
|
+
import type { ViewProps } from '@instructure/ui-view/v11_6'
|
|
36
36
|
import { MouseEvent } from 'react'
|
|
37
37
|
import { Renderable } from '@instructure/shared-types'
|
|
38
38
|
type HeroIconSize = 'medium' | 'x-large' | 'large'
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
---
|
|
2
|
+
describes: Billboard
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
### Static Billboard
|
|
6
|
+
|
|
7
|
+
Used for empty states, 404 pages, redirects, etc.
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
---
|
|
11
|
+
type: example
|
|
12
|
+
---
|
|
13
|
+
<Billboard
|
|
14
|
+
size="medium"
|
|
15
|
+
heading="Well, this is awkward."
|
|
16
|
+
message="Think there should be something here?"
|
|
17
|
+
hero={<Img src={placeholderImage(900, 500)} />}
|
|
18
|
+
/>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Structure
|
|
22
|
+
|
|
23
|
+
- If Billboard has an `href` prop set, it will render as a link;
|
|
24
|
+
if an `onClick` prop is set, the component will render as a button.
|
|
25
|
+
- Use the `message` prop for your link or button text/call to action (Note:
|
|
26
|
+
don't pass interactive content to the `message` prop if you have set the `href`
|
|
27
|
+
or `onClick` props).
|
|
28
|
+
- Use the `size` prop to adjust the size of the icon and text.
|
|
29
|
+
- Pass [Instructure icons](icons-react) to the `hero` property via a function
|
|
30
|
+
_(see examples)_, and they will be sized correctly based on the Billboard's
|
|
31
|
+
`size`.
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
---
|
|
35
|
+
type: example
|
|
36
|
+
---
|
|
37
|
+
<View as="div" width="400px" withVisualDebug>
|
|
38
|
+
<Billboard
|
|
39
|
+
margin="large"
|
|
40
|
+
heading="404"
|
|
41
|
+
message="Billboard is now a button"
|
|
42
|
+
size="small"
|
|
43
|
+
onClick={function () {
|
|
44
|
+
alert('This Billboard was clicked!')
|
|
45
|
+
}}
|
|
46
|
+
hero={(size) => <UserInstUIIcon size={size} />}
|
|
47
|
+
/>
|
|
48
|
+
</View>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
---
|
|
53
|
+
type: example
|
|
54
|
+
---
|
|
55
|
+
<View as="div" width="600px" withVisualDebug>
|
|
56
|
+
<Billboard
|
|
57
|
+
margin="large"
|
|
58
|
+
message="Click this link"
|
|
59
|
+
href="http://instructure.com"
|
|
60
|
+
hero={(size) => <BookCheckInstUIIcon size={size} />}
|
|
61
|
+
/>
|
|
62
|
+
</View>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
---
|
|
67
|
+
type: example
|
|
68
|
+
---
|
|
69
|
+
<Billboard
|
|
70
|
+
readOnly
|
|
71
|
+
message="Create a new Module"
|
|
72
|
+
size="large"
|
|
73
|
+
onClick={function () {
|
|
74
|
+
alert('This Billboard was clicked!')
|
|
75
|
+
}}
|
|
76
|
+
hero={(size) => <PlusInstUIIcon size={size} />}
|
|
77
|
+
/>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Disabled Billboard
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
---
|
|
84
|
+
type: example
|
|
85
|
+
---
|
|
86
|
+
<Billboard
|
|
87
|
+
size="small"
|
|
88
|
+
heading="This is disabled"
|
|
89
|
+
onClick={function () {
|
|
90
|
+
alert('This Billboard was clicked!')
|
|
91
|
+
}}
|
|
92
|
+
hero={(size) => <UserInstUIIcon size={size} />}
|
|
93
|
+
disabled
|
|
94
|
+
/>
|
|
95
|
+
```
|
|
@@ -0,0 +1,202 @@
|
|
|
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, MouseEvent } from 'react'
|
|
26
|
+
|
|
27
|
+
import { Heading } from '@instructure/ui-heading/latest'
|
|
28
|
+
import { View } from '@instructure/ui-view/latest'
|
|
29
|
+
import {
|
|
30
|
+
omitProps,
|
|
31
|
+
callRenderProp,
|
|
32
|
+
getElementType
|
|
33
|
+
} from '@instructure/ui-react-utils'
|
|
34
|
+
import { renderIconWithProps } from '@instructure/ui-icons'
|
|
35
|
+
|
|
36
|
+
import { withStyle } from '@instructure/emotion'
|
|
37
|
+
|
|
38
|
+
import generateStyle from './styles'
|
|
39
|
+
|
|
40
|
+
import { allowedProps } from './props'
|
|
41
|
+
import type { BillboardProps } from './props'
|
|
42
|
+
import type { ViewProps } from '@instructure/ui-view/latest'
|
|
43
|
+
|
|
44
|
+
// Map Billboard sizes to icon sizes
|
|
45
|
+
const billboardSizeToIconSize = {
|
|
46
|
+
small: 'illu-sm',
|
|
47
|
+
medium: 'illu-md',
|
|
48
|
+
large: 'illu-lg'
|
|
49
|
+
} as const
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
---
|
|
53
|
+
category: components
|
|
54
|
+
---
|
|
55
|
+
**/
|
|
56
|
+
@withStyle(generateStyle)
|
|
57
|
+
class Billboard extends Component<
|
|
58
|
+
BillboardProps,
|
|
59
|
+
{ isHovered: boolean; isActive: boolean }
|
|
60
|
+
> {
|
|
61
|
+
static readonly componentId = 'Billboard'
|
|
62
|
+
|
|
63
|
+
static allowedProps = allowedProps
|
|
64
|
+
static defaultProps = {
|
|
65
|
+
disabled: false,
|
|
66
|
+
readOnly: false,
|
|
67
|
+
size: 'medium',
|
|
68
|
+
headingAs: 'span',
|
|
69
|
+
headingLevel: 'h1',
|
|
70
|
+
as: 'span',
|
|
71
|
+
elementRef: () => {}
|
|
72
|
+
} as const
|
|
73
|
+
|
|
74
|
+
state = {
|
|
75
|
+
isHovered: false,
|
|
76
|
+
isActive: false
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
ref: Element | null = null
|
|
80
|
+
|
|
81
|
+
handleRef = (el: Element | null) => {
|
|
82
|
+
const { elementRef } = this.props
|
|
83
|
+
|
|
84
|
+
this.ref = el
|
|
85
|
+
|
|
86
|
+
if (typeof elementRef === 'function') {
|
|
87
|
+
elementRef(el)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
componentDidMount() {
|
|
92
|
+
this.props.makeStyles?.()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
componentDidUpdate() {
|
|
96
|
+
this.props.makeStyles?.()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
renderHeading() {
|
|
100
|
+
const { headingLevel, headingAs, heading, styles } = this.props
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<span css={styles?.heading}>
|
|
104
|
+
<Heading level={headingLevel} as={headingAs} color="primary">
|
|
105
|
+
{heading}
|
|
106
|
+
</Heading>
|
|
107
|
+
</span>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
handleMouseEnter = () => {
|
|
112
|
+
this.setState({ isHovered: true })
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
handleMouseLeave = () => {
|
|
116
|
+
this.setState({ isHovered: false, isActive: false })
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
handleMouseDown = () => {
|
|
120
|
+
this.setState({ isActive: true })
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
handleMouseUp = () => {
|
|
124
|
+
this.setState({ isActive: false })
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
renderHero() {
|
|
128
|
+
const { hero, size } = this.props
|
|
129
|
+
const { isHovered, isActive } = this.state
|
|
130
|
+
|
|
131
|
+
if (!hero) return null
|
|
132
|
+
|
|
133
|
+
const iconSize = billboardSizeToIconSize[size!]
|
|
134
|
+
// Priority: active > hover > default
|
|
135
|
+
const iconColor = isActive
|
|
136
|
+
? 'onColor'
|
|
137
|
+
: isHovered
|
|
138
|
+
? 'infoColor'
|
|
139
|
+
: 'baseColor'
|
|
140
|
+
|
|
141
|
+
return renderIconWithProps(hero, iconSize, iconColor)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
renderContent() {
|
|
145
|
+
const { heading, message, hero, styles } = this.props
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<span css={styles?.content}>
|
|
149
|
+
{hero && <span css={styles?.hero}>{this.renderHero()}</span>}
|
|
150
|
+
{heading && this.renderHeading()}
|
|
151
|
+
{message && (
|
|
152
|
+
<span css={styles?.message}>{callRenderProp(message)}</span>
|
|
153
|
+
)}
|
|
154
|
+
</span>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
handleClick = (e: MouseEvent<ViewProps & Element>): void => {
|
|
159
|
+
const { readOnly, onClick } = this.props
|
|
160
|
+
|
|
161
|
+
if (readOnly) {
|
|
162
|
+
e.preventDefault()
|
|
163
|
+
e.stopPropagation()
|
|
164
|
+
} else if (typeof onClick === 'function') {
|
|
165
|
+
onClick(e)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
render() {
|
|
170
|
+
const { href, disabled, readOnly, margin, styles } = this.props
|
|
171
|
+
|
|
172
|
+
const Element = getElementType(Billboard, this.props)
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<View as="div" margin={margin}>
|
|
176
|
+
<View
|
|
177
|
+
{...omitProps(this.props, [
|
|
178
|
+
...Billboard.allowedProps,
|
|
179
|
+
...View.allowedProps
|
|
180
|
+
])}
|
|
181
|
+
type={Element === 'button' ? 'button' : undefined}
|
|
182
|
+
as={Element}
|
|
183
|
+
elementRef={this.handleRef}
|
|
184
|
+
css={styles?.billboard}
|
|
185
|
+
href={href}
|
|
186
|
+
onClick={this.handleClick}
|
|
187
|
+
onMouseEnter={this.handleMouseEnter}
|
|
188
|
+
onMouseLeave={this.handleMouseLeave}
|
|
189
|
+
onMouseDown={this.handleMouseDown}
|
|
190
|
+
onMouseUp={this.handleMouseUp}
|
|
191
|
+
disabled={disabled}
|
|
192
|
+
aria-disabled={disabled || readOnly ? 'true' : undefined}
|
|
193
|
+
>
|
|
194
|
+
{this.renderContent()}
|
|
195
|
+
</View>
|
|
196
|
+
</View>
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export default Billboard
|
|
202
|
+
export { Billboard }
|