@instructure/ui-img 11.7.2-snapshot-41 → 11.7.2-snapshot-46
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 +12 -2
- package/es/Img/v2/index.js +126 -0
- package/es/Img/v2/props.js +26 -0
- package/es/Img/v2/styles.js +132 -0
- package/es/exports/b.js +24 -0
- package/lib/Img/v2/index.js +131 -0
- package/lib/Img/v2/props.js +31 -0
- package/lib/Img/v2/styles.js +138 -0
- package/lib/exports/b.js +12 -0
- package/package.json +20 -19
- package/src/Img/v2/README.md +124 -0
- package/src/Img/v2/index.tsx +139 -0
- package/src/Img/v2/props.ts +89 -0
- package/src/Img/v2/styles.ts +149 -0
- package/src/exports/b.ts +25 -0
- package/tsconfig.build.json +1 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Img/v2/index.d.ts +42 -0
- package/types/Img/v2/index.d.ts.map +1 -0
- package/types/Img/v2/props.d.ts +41 -0
- package/types/Img/v2/props.d.ts.map +1 -0
- package/types/Img/v2/styles.d.ts +15 -0
- package/types/Img/v2/styles.d.ts.map +1 -0
- package/types/exports/b.d.ts +3 -0
- package/types/exports/b.d.ts.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-img",
|
|
3
|
-
"version": "11.7.2-snapshot-
|
|
3
|
+
"version": "11.7.2-snapshot-46",
|
|
4
4
|
"description": "An accessible image component.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -15,20 +15,21 @@
|
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@babel/runtime": "^7.27.6",
|
|
18
|
-
"@instructure/console": "11.7.2-snapshot-
|
|
19
|
-
"@instructure/shared-types": "11.7.2-snapshot-
|
|
20
|
-
"@instructure/
|
|
21
|
-
"@instructure/ui-dom-utils": "11.7.2-snapshot-
|
|
22
|
-
"@instructure/
|
|
23
|
-
"@instructure/ui-
|
|
18
|
+
"@instructure/console": "11.7.2-snapshot-46",
|
|
19
|
+
"@instructure/shared-types": "11.7.2-snapshot-46",
|
|
20
|
+
"@instructure/ui-react-utils": "11.7.2-snapshot-46",
|
|
21
|
+
"@instructure/ui-dom-utils": "11.7.2-snapshot-46",
|
|
22
|
+
"@instructure/emotion": "11.7.2-snapshot-46",
|
|
23
|
+
"@instructure/ui-themes": "11.7.2-snapshot-46",
|
|
24
|
+
"@instructure/ui-view": "11.7.2-snapshot-46"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"@testing-library/jest-dom": "^6.6.3",
|
|
27
28
|
"@testing-library/react": "15.0.7",
|
|
28
29
|
"@testing-library/user-event": "^14.6.1",
|
|
29
30
|
"vitest": "^3.2.2",
|
|
30
|
-
"@instructure/ui-axe-check": "11.7.2-snapshot-
|
|
31
|
-
"@instructure/ui-babel-preset": "11.7.2-snapshot-
|
|
31
|
+
"@instructure/ui-axe-check": "11.7.2-snapshot-46",
|
|
32
|
+
"@instructure/ui-babel-preset": "11.7.2-snapshot-46"
|
|
32
33
|
},
|
|
33
34
|
"peerDependencies": {
|
|
34
35
|
"react": ">=18 <=19"
|
|
@@ -58,18 +59,18 @@
|
|
|
58
59
|
"default": "./es/exports/a.js"
|
|
59
60
|
},
|
|
60
61
|
"./v11_7": {
|
|
61
|
-
"src": "./src/exports/
|
|
62
|
-
"types": "./types/exports/
|
|
63
|
-
"import": "./es/exports/
|
|
64
|
-
"require": "./lib/exports/
|
|
65
|
-
"default": "./es/exports/
|
|
62
|
+
"src": "./src/exports/b.ts",
|
|
63
|
+
"types": "./types/exports/b.d.ts",
|
|
64
|
+
"import": "./es/exports/b.js",
|
|
65
|
+
"require": "./lib/exports/b.js",
|
|
66
|
+
"default": "./es/exports/b.js"
|
|
66
67
|
},
|
|
67
68
|
"./latest": {
|
|
68
|
-
"src": "./src/exports/
|
|
69
|
-
"types": "./types/exports/
|
|
70
|
-
"import": "./es/exports/
|
|
71
|
-
"require": "./lib/exports/
|
|
72
|
-
"default": "./es/exports/
|
|
69
|
+
"src": "./src/exports/b.ts",
|
|
70
|
+
"types": "./types/exports/b.d.ts",
|
|
71
|
+
"import": "./es/exports/b.js",
|
|
72
|
+
"require": "./lib/exports/b.js",
|
|
73
|
+
"default": "./es/exports/b.js"
|
|
73
74
|
}
|
|
74
75
|
},
|
|
75
76
|
"scripts": {
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
---
|
|
2
|
+
describes: Img
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
An accessible image component
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
---
|
|
9
|
+
type: example
|
|
10
|
+
---
|
|
11
|
+
<Img src={placeholderImage(250, 250)} />
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### Margin and display
|
|
15
|
+
|
|
16
|
+
Use the `margin` prop to add space around `<Img />`. Setting the `display` prop to `block` makes
|
|
17
|
+
the image a block-level element.
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
---
|
|
21
|
+
type: example
|
|
22
|
+
---
|
|
23
|
+
<View textAlign="center" as="div">
|
|
24
|
+
<Img margin="small" alt="A placeholder image" src={placeholderImage(300, 200)} />
|
|
25
|
+
<Img margin="small" src={placeholderImage(200, 200)} />
|
|
26
|
+
<Img display="block" margin="small auto" src={placeholderImage(400, 200)} />
|
|
27
|
+
</View>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Color overlay
|
|
31
|
+
|
|
32
|
+
The `overlay` prop accepts parameters for `color`, `opacity`, and `blend`.
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
---
|
|
36
|
+
type: example
|
|
37
|
+
---
|
|
38
|
+
<View textAlign="center" as="div">
|
|
39
|
+
<Img
|
|
40
|
+
src={placeholderImage(200, 200)}
|
|
41
|
+
overlay={{color: '#0374B5', opacity: 9, blend: 'overlay'}}
|
|
42
|
+
alt="A placeholder image"
|
|
43
|
+
margin="x-small"
|
|
44
|
+
/>
|
|
45
|
+
<Img
|
|
46
|
+
src={placeholderImage(200, 200)}
|
|
47
|
+
overlay={{color: '#0374B5', opacity: 6, blend: 'multiply'}}
|
|
48
|
+
alt="A placeholder image"
|
|
49
|
+
margin="x-small"
|
|
50
|
+
/>
|
|
51
|
+
<Img
|
|
52
|
+
src={placeholderImage(200, 200)}
|
|
53
|
+
overlay={{color: '#0374B5', opacity: 3}}
|
|
54
|
+
alt="A placeholder image"
|
|
55
|
+
margin="x-small"
|
|
56
|
+
/>
|
|
57
|
+
</View>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Cover
|
|
61
|
+
|
|
62
|
+
When the `constrain` prop is set to `cover` the image fills the _full_ width and height of its
|
|
63
|
+
containing element, while maintaining the aspect ratio of the source image.
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
---
|
|
67
|
+
type: example
|
|
68
|
+
---
|
|
69
|
+
<div style={{width: '66%', height: '11rem'}}>
|
|
70
|
+
<Img src={avatarSquare} constrain="cover" />
|
|
71
|
+
</div>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Contain
|
|
75
|
+
|
|
76
|
+
When the `constrain` prop is set to `contain` the image fits within the width and height of its
|
|
77
|
+
containing element, while maintaining the aspect ratio of the source image.
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
---
|
|
81
|
+
type: example
|
|
82
|
+
---
|
|
83
|
+
<View as="div" background="primary-inverse" width="200px" height="200px" textAlign="center">
|
|
84
|
+
<Img src={avatarPortrait} constrain="contain" />
|
|
85
|
+
</View>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Grayscale and blur filters
|
|
89
|
+
|
|
90
|
+
Please note: these should only be used for presentational effects.
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
---
|
|
94
|
+
type: example
|
|
95
|
+
---
|
|
96
|
+
<View textAlign="center" as="div">
|
|
97
|
+
<Img
|
|
98
|
+
withGrayscale
|
|
99
|
+
src={avatarSquare}
|
|
100
|
+
alt="A placeholder image"
|
|
101
|
+
margin="x-small"
|
|
102
|
+
/>
|
|
103
|
+
<Img
|
|
104
|
+
withBlur
|
|
105
|
+
src={avatarSquare}
|
|
106
|
+
alt="A placeholder image"
|
|
107
|
+
margin="x-small"
|
|
108
|
+
/>
|
|
109
|
+
</View>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Guidelines
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
---
|
|
116
|
+
type: embed
|
|
117
|
+
---
|
|
118
|
+
<Guidelines>
|
|
119
|
+
<Figure recommendation="a11y" title="Accessibility">
|
|
120
|
+
<Figure.Item>Contextual images must have alternative text that describes the information or function represented by them</Figure.Item>
|
|
121
|
+
<Figure.Item>Decorative images that do not present important content, are used for layout or non-informative purposes, and do not appear within a link do not need to be presented to screen readers. Decorative and spacer images should have null alternative text (alt="")</Figure.Item>
|
|
122
|
+
</Figure>
|
|
123
|
+
</Guidelines>
|
|
124
|
+
```
|
|
@@ -0,0 +1,139 @@
|
|
|
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 { View } from '@instructure/ui-view/latest'
|
|
28
|
+
import { passthroughProps } from '@instructure/ui-react-utils'
|
|
29
|
+
|
|
30
|
+
import { withStyle } from '@instructure/emotion'
|
|
31
|
+
|
|
32
|
+
import generateStyle from './styles'
|
|
33
|
+
|
|
34
|
+
import { allowedProps } from './props'
|
|
35
|
+
import type { ImgProps } from './props'
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
---
|
|
39
|
+
category: components
|
|
40
|
+
---
|
|
41
|
+
**/
|
|
42
|
+
@withStyle(generateStyle)
|
|
43
|
+
class Img extends Component<ImgProps> {
|
|
44
|
+
static readonly componentId = 'Img'
|
|
45
|
+
|
|
46
|
+
static allowedProps = allowedProps
|
|
47
|
+
static defaultProps = {
|
|
48
|
+
alt: '',
|
|
49
|
+
display: 'inline-block',
|
|
50
|
+
withGrayscale: false,
|
|
51
|
+
withBlur: false
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
ref: Element | null = null
|
|
55
|
+
|
|
56
|
+
handleRef = (el: Element | null) => {
|
|
57
|
+
const { elementRef } = this.props
|
|
58
|
+
|
|
59
|
+
this.ref = el
|
|
60
|
+
|
|
61
|
+
if (typeof elementRef === 'function') {
|
|
62
|
+
elementRef(el)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
componentDidMount() {
|
|
67
|
+
this.props.makeStyles?.()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
componentDidUpdate() {
|
|
71
|
+
this.props.makeStyles?.()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
render() {
|
|
75
|
+
const {
|
|
76
|
+
src,
|
|
77
|
+
alt,
|
|
78
|
+
margin,
|
|
79
|
+
display,
|
|
80
|
+
overlay,
|
|
81
|
+
withGrayscale,
|
|
82
|
+
withBlur,
|
|
83
|
+
constrain,
|
|
84
|
+
width,
|
|
85
|
+
height,
|
|
86
|
+
elementRef,
|
|
87
|
+
styles,
|
|
88
|
+
loading,
|
|
89
|
+
...props
|
|
90
|
+
} = this.props
|
|
91
|
+
|
|
92
|
+
const a11yProps = {
|
|
93
|
+
alt: alt || ''
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const imageProps = {
|
|
97
|
+
css: styles?.img,
|
|
98
|
+
src,
|
|
99
|
+
loading
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const containerProps = {
|
|
103
|
+
...passthroughProps(props),
|
|
104
|
+
width,
|
|
105
|
+
height,
|
|
106
|
+
margin,
|
|
107
|
+
display,
|
|
108
|
+
elementRef: this.handleRef
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (overlay) {
|
|
112
|
+
// if a background image is rendered we add the a11y props on the container element
|
|
113
|
+
const rootProps = {
|
|
114
|
+
...containerProps
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<View {...rootProps} as="span" css={styles?.container} data-cid="Img">
|
|
119
|
+
{/* eslint-disable-next-line jsx-a11y/alt-text*/}
|
|
120
|
+
{<img {...imageProps} {...a11yProps} />}
|
|
121
|
+
{overlay && <span css={styles?.overlay} />}
|
|
122
|
+
</View>
|
|
123
|
+
)
|
|
124
|
+
} else {
|
|
125
|
+
return (
|
|
126
|
+
<View
|
|
127
|
+
{...containerProps}
|
|
128
|
+
{...imageProps}
|
|
129
|
+
{...a11yProps}
|
|
130
|
+
as="img"
|
|
131
|
+
data-cid="Img"
|
|
132
|
+
/>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export default Img
|
|
139
|
+
export { Img }
|
|
@@ -0,0 +1,89 @@
|
|
|
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 { OtherHTMLAttributes } from '@instructure/shared-types'
|
|
26
|
+
import type {
|
|
27
|
+
Spacing,
|
|
28
|
+
WithStyleProps,
|
|
29
|
+
ComponentStyle
|
|
30
|
+
} from '@instructure/emotion'
|
|
31
|
+
import type { NewComponentTypes } from '@instructure/ui-themes'
|
|
32
|
+
|
|
33
|
+
type ImgOwnProps = {
|
|
34
|
+
src: string
|
|
35
|
+
alt?: string
|
|
36
|
+
display?: 'inline-block' | 'block'
|
|
37
|
+
/**
|
|
38
|
+
* Gets passed down to the img component. Same as the native HTML img's loading attribute
|
|
39
|
+
*/
|
|
40
|
+
loading?: 'eager' | 'lazy'
|
|
41
|
+
/**
|
|
42
|
+
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
43
|
+
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
44
|
+
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
45
|
+
*/
|
|
46
|
+
margin?: Spacing
|
|
47
|
+
/**
|
|
48
|
+
* Valid values for `opacity` are `0` - `10`. Valid values for `blend` are
|
|
49
|
+
* `normal` (default), `multiply`, `screen`, `overlay`, and `color-burn`.
|
|
50
|
+
*/
|
|
51
|
+
overlay?: {
|
|
52
|
+
color: string
|
|
53
|
+
opacity: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
|
|
54
|
+
blend?: 'normal' | 'multiply' | 'screen' | 'overlay' | 'color-burn'
|
|
55
|
+
}
|
|
56
|
+
withGrayscale?: boolean
|
|
57
|
+
withBlur?: boolean
|
|
58
|
+
constrain?: 'cover' | 'contain'
|
|
59
|
+
elementRef?: (element: Element | null) => void
|
|
60
|
+
height?: string | number
|
|
61
|
+
width?: string | number
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
type PropKeys = keyof ImgOwnProps
|
|
65
|
+
|
|
66
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
67
|
+
|
|
68
|
+
type ImgProps = ImgOwnProps &
|
|
69
|
+
WithStyleProps<NewComponentTypes['Img'], ImgStyle> &
|
|
70
|
+
OtherHTMLAttributes<ImgOwnProps>
|
|
71
|
+
|
|
72
|
+
type ImgStyle = ComponentStyle<'overlay' | 'container' | 'img'>
|
|
73
|
+
const allowedProps: AllowedPropKeys = [
|
|
74
|
+
'src',
|
|
75
|
+
'alt',
|
|
76
|
+
'display',
|
|
77
|
+
'loading',
|
|
78
|
+
'margin',
|
|
79
|
+
'overlay',
|
|
80
|
+
'withGrayscale',
|
|
81
|
+
'withBlur',
|
|
82
|
+
'constrain',
|
|
83
|
+
'elementRef',
|
|
84
|
+
'height',
|
|
85
|
+
'width'
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
export type { ImgProps, ImgStyle }
|
|
89
|
+
export { allowedProps }
|
|
@@ -0,0 +1,149 @@
|
|
|
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 { NewComponentTypes } from '@instructure/ui-themes'
|
|
26
|
+
import type { ImgProps, ImgStyle } 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: NewComponentTypes['Img'],
|
|
40
|
+
props: ImgProps
|
|
41
|
+
): ImgStyle => {
|
|
42
|
+
const { overlay, withBlur, withGrayscale, constrain } = props
|
|
43
|
+
|
|
44
|
+
const isCover = constrain === 'cover'
|
|
45
|
+
const isContain = constrain === 'contain'
|
|
46
|
+
|
|
47
|
+
// if overlay or filters are updated via props,
|
|
48
|
+
// make the transition look smooth
|
|
49
|
+
const transitionStyle = {
|
|
50
|
+
transition: `all ${componentTheme.effectTransitionDuration}`
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const getFilterStyle = () => {
|
|
54
|
+
const filters = []
|
|
55
|
+
|
|
56
|
+
withBlur && filters.push(`blur(${componentTheme.imageBlurAmount})`)
|
|
57
|
+
withGrayscale && filters.push('grayscale(1)')
|
|
58
|
+
|
|
59
|
+
return filters.length > 0
|
|
60
|
+
? {
|
|
61
|
+
...transitionStyle,
|
|
62
|
+
filter: filters.join(' ')
|
|
63
|
+
}
|
|
64
|
+
: {
|
|
65
|
+
filter: 'none'
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const fillContainer = {
|
|
70
|
+
width: '100%',
|
|
71
|
+
height: '100%'
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const imgCoverStyle = {
|
|
75
|
+
objectFit: 'cover',
|
|
76
|
+
...fillContainer
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const imgContainStyle = {
|
|
80
|
+
objectFit: 'contain',
|
|
81
|
+
...fillContainer,
|
|
82
|
+
...(overlay && {
|
|
83
|
+
width: 'auto',
|
|
84
|
+
height: 'auto',
|
|
85
|
+
maxWidth: '100%',
|
|
86
|
+
maxHeight: '100%'
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
overlay: {
|
|
92
|
+
label: 'img__overlay',
|
|
93
|
+
position: 'absolute',
|
|
94
|
+
top: '0px',
|
|
95
|
+
left: '0px',
|
|
96
|
+
width: '100%',
|
|
97
|
+
height: '100%',
|
|
98
|
+
...transitionStyle,
|
|
99
|
+
...(overlay && {
|
|
100
|
+
backgroundColor: overlay.color,
|
|
101
|
+
opacity: overlay.opacity * 0.1,
|
|
102
|
+
mixBlendMode: overlay.blend ? overlay.blend : undefined
|
|
103
|
+
})
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
container: {
|
|
107
|
+
label: 'img__container',
|
|
108
|
+
...(overlay && {
|
|
109
|
+
position: 'relative',
|
|
110
|
+
overflow:
|
|
111
|
+
'hidden' /* stops blurred images extending past overlay borders */
|
|
112
|
+
}),
|
|
113
|
+
...(isCover && fillContainer),
|
|
114
|
+
...(isContain && { height: 'inherit' })
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
img: {
|
|
118
|
+
label: 'img',
|
|
119
|
+
// reset image styles (initial: all was causing conflicts
|
|
120
|
+
// View's CSS and overriding height/width attrs)
|
|
121
|
+
margin: '0',
|
|
122
|
+
padding: '0',
|
|
123
|
+
float: 'none',
|
|
124
|
+
top: 'auto',
|
|
125
|
+
bottom: 'auto',
|
|
126
|
+
left: 'auto',
|
|
127
|
+
right: 'auto',
|
|
128
|
+
lineHeight: 'normal',
|
|
129
|
+
position: 'static',
|
|
130
|
+
transform: 'none',
|
|
131
|
+
maxHeight: 'none',
|
|
132
|
+
minHeight: '0',
|
|
133
|
+
minWidth: '0',
|
|
134
|
+
maxWidth: '100%',
|
|
135
|
+
|
|
136
|
+
...getFilterStyle(),
|
|
137
|
+
|
|
138
|
+
...(overlay && {
|
|
139
|
+
// when image is contained in overlay,
|
|
140
|
+
// avoid extra space at bottom from inline/line-height
|
|
141
|
+
display: 'block'
|
|
142
|
+
}),
|
|
143
|
+
...(isCover && imgCoverStyle),
|
|
144
|
+
...(isContain && imgContainStyle)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export default generateStyle
|
package/src/exports/b.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
export { Img } from '../Img/v2'
|
|
25
|
+
export type { ImgProps } from '../Img/v2/props'
|
package/tsconfig.build.json
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
{ "path": "../shared-types/tsconfig.build.json" },
|
|
13
13
|
{ "path": "../ui-dom-utils/tsconfig.build.json" },
|
|
14
14
|
{ "path": "../ui-react-utils/tsconfig.build.json" },
|
|
15
|
+
{ "path": "../ui-themes/tsconfig.build.json" },
|
|
15
16
|
{ "path": "../ui-view/tsconfig.build.json" },
|
|
16
17
|
{ "path": "../ui-babel-preset/tsconfig.build.json" },
|
|
17
18
|
{ "path": "../ui-axe-check/tsconfig.build.json" }
|