|
| 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 { ImgTheme, OtherHTMLAttributes } from '@instructure/shared-types' |
| 26 | +import type { |
| 27 | + Spacing, |
| 28 | + WithStyleProps, |
| 29 | + ComponentStyle |
| 30 | +} from '@instructure/emotion' |
| 31 | + |
| 32 | +type ImgOwnProps = { |
| 33 | + src: string |
| 34 | + alt?: string |
| 35 | + display?: 'inline-block' | 'block' |
| 36 | + /** |
| 37 | + * Gets passed down to the img component. Same as the native HTML img's loading attribute |
| 38 | + */ |
| 39 | + loading?: 'eager' | 'lazy' |
| 40 | + /** |
| 41 | + * Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`, |
| 42 | + * `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via |
| 43 | + * familiar CSS-like shorthand. For example: `margin="small auto large"`. |
| 44 | + */ |
| 45 | + margin?: Spacing |
| 46 | + /** |
| 47 | + * Valid values for `opacity` are `0` - `10`. Valid values for `blend` are |
| 48 | + * `normal` (default), `multiply`, `screen`, `overlay`, and `color-burn`. |
| 49 | + */ |
| 50 | + overlay?: { |
| 51 | + color: string |
| 52 | + opacity: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 53 | + blend?: 'normal' | 'multiply' | 'screen' | 'overlay' | 'color-burn' |
| 54 | + } |
| 55 | + withGrayscale?: boolean |
| 56 | + withBlur?: boolean |
| 57 | + constrain?: 'cover' | 'contain' |
| 58 | + elementRef?: (element: Element | null) => void |
| 59 | + height?: string | number |
| 60 | + width?: string | number |
| 61 | +} |
| 62 | + |
| 63 | +type PropKeys = keyof ImgOwnProps |
| 64 | + |
| 65 | +type AllowedPropKeys = Readonly<Array<PropKeys>> |
| 66 | + |
| 67 | +type ImgProps = ImgOwnProps & |
| 68 | + WithStyleProps<ImgTheme, ImgStyle> & |
| 69 | + OtherHTMLAttributes<ImgOwnProps> |
| 70 | + |
| 71 | +type ImgStyle = ComponentStyle<'overlay' | 'container' | 'img'> |
| 72 | +const allowedProps: AllowedPropKeys = [ |
| 73 | + 'src', |
| 74 | + 'alt', |
| 75 | + 'display', |
| 76 | + 'loading', |
| 77 | + 'margin', |
| 78 | + 'overlay', |
| 79 | + 'withGrayscale', |
| 80 | + 'withBlur', |
| 81 | + 'constrain', |
| 82 | + 'elementRef', |
| 83 | + 'height', |
| 84 | + 'width' |
| 85 | +] |
| 86 | + |
| 87 | +export type { ImgProps, ImgStyle } |
| 88 | +export { allowedProps } |
0 commit comments