-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIRROR] Typescript image component [MDB IGNORE] (#25699) (#1188)
* Typescript image component (#80291) No longer rely on Box to create images. A pretty simple change for most UIs. Solves a kinda weird solution for image rendering we had in Box. Did some small refactors along the way. Emojipedia is in TS now. Bug fix Fixes #80282 🆑 fix: Emojipedia shouldn't bluescreen anymore. /🆑 * Typescript image component --------- Co-authored-by: SkyratBot <[email protected]> Co-authored-by: Jeremiah <[email protected]>
- Loading branch information
1 parent
3fb55e2
commit bca6148
Showing
25 changed files
with
237 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ReactNode } from 'react'; | ||
import { BoxProps, computeBoxProps } from './Box'; | ||
import { Tooltip } from './Tooltip'; | ||
|
||
type Props = Partial<{ | ||
fixBlur: boolean; // true is default, this is an ie thing | ||
objectFit: 'contain' | 'cover'; // fill is default | ||
tooltip: ReactNode; | ||
}> & | ||
IconUnion & | ||
BoxProps; | ||
|
||
// at least one of these is required | ||
type IconUnion = | ||
| { | ||
className?: string; | ||
src: string; | ||
} | ||
| { | ||
className: string; | ||
src?: string; | ||
}; | ||
|
||
/** Image component. Use this instead of Box as="img". */ | ||
export const Image = (props: Props) => { | ||
const { | ||
className, | ||
fixBlur = true, | ||
objectFit = 'fill', | ||
src, | ||
tooltip, | ||
...rest | ||
} = props; | ||
|
||
const computedStyle = { | ||
...computeBoxProps(rest).style, | ||
'-ms-interpolation-mode': fixBlur ? 'nearest-neighbor' : 'auto', | ||
objectFit, | ||
}; | ||
|
||
let content = <img className={className} src={src} style={computedStyle} />; | ||
|
||
if (tooltip) { | ||
content = <Tooltip content={tooltip}>{content}</Tooltip>; | ||
} | ||
|
||
return content; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.