--- layout: docs title: RetinaImg edit_url: "https://github.com/nylas/N1/blob/master/src/components/retina-img.cjsx" ---
RetinaImg wraps the DOM's standard <img
> tag and implements a UIImage
style
interface. Rather than specifying an image src
, RetinaImg allows you to provide
an image name. Like UIImage on iOS, it automatically finds the best image for the current
display based on pixel density. Given image.png
, on a Retina screen, it looks for
image@2x.png
, image.png
, image@1x.png
in that order. It uses a lookup table and caches
image names, so images generally resolve immediately.
RetinaImg also introduces the concept of image modes
. Specifying an image mode
is important for theming: it describes the content of your image, allowing theme
developers to properly adjust it. The four modes are described below:
content-light
CSS class to the image.content-dark
CSS class to the image.background-color
of the RetinaImg. This mode adds the
content-mask
CSS class to the image, and leverages -webkit-mask-image
.
Example: Icons displayed within buttons specify ContentIsMask, and their
color is declared via CSS to be the same as the button text color. Changing
@text-color-subtle
in a theme changes both button text and button icons! .btn-icon {
color: @text-color-subtle;
img.content-mask { background-color:@text-color-subtle; }
}
React props
supported by RetinaImg:
mode |
(required) One of the RetinaImg.Mode constants. See above for details. |
name |
Optional
A String image name to display. |
url |
Optional
A String url of an image to display. May be an http, https, or |
fallback |
Optional
A String image name to use when |
selected |
Optional
Appends "-selected" to the end of the image name when when true |
active |
Optional
Appends "-active" to the end of the image name when when true |
style |
Optional
An Object with additional styles to apply to the image. |
resourcePath |
(options) Changes the default lookup location used to find the images. |