Hi All!
I’m excited to share a proposal for a new experimental feature that allows authors to wrap images and videos inside device frames.
When developing UI libraries or apps, we sometimes need to show previews of how things look when rendered on a device, like a phone or a tablet. This new experimental feature is set to allow you to wrap your images and videos in a frame, making it easier to create complex assets and maintain them overtime.
DeviceFrames are supposed to work in tandem with captions for both @Image
and @Video
.
@Image
Add the following parameters to the @Image
directive:
-
deviceFrame
: Freeform string input. See Adding your own frames*
@Image(
source: "overview-hero.png",
alt: "A screenshot of an app containing an illustration of a sleeping sloth.",
deviceFrame: phone
)
Explanation: Wraps the image inside a device frame, with the caption right under it. Images that do not fit the device frame’s aspect ratios are top aligned and stretched to fit the width.
Examples
@Image(
source: "some-image",
deviceFrame: phone
)
-
deviceFrameCrop
: One oftopHalf
,bottomHalf
. Defaults tonone
, resulting in no cropping.
@Image(
source: "notification.png",
alt: "A screenshot of an app notification.",
deviceFrame: phone,
deviceFrameCrop: topHalf,
)
Explanation: Renders only the top/bottom half of a frame, re-calculating the aspect ratio and size of the frame. This allows authors to focus user’s attention to either part of the device.
@Video
Add the following parameter to the @Video
directive:
-
deviceFrame
: Freeform string input. See Adding your own frames*
Examples
@Video(
source: "page-controls-scrub.mp4",
poster: "page-controls-scrub.png",
deviceFrame: tablet,
)
-
deviceFrameCrop
: One oftopHalf
,bottomHalf
. Defaults tonone
, resulting in no cropping.
@Video(
source: "video.mp4",
deviceFrame: tv,
deviceFrameCrop: bottomHalf,
)
Explanation: Renders only the top/bottom half of a frame, re-calculating the aspect ratio and size of the frame. This allows authors to focus user’s attention to either part of the device.
Adding your own frames
Device frames can be added using the theme-settings.json
file. Add all your frames under the theme.device-frames
path, then use the same keys you defined for your deviceFrame
when you author your docs.
All the parameters are required.
- The Numeric values represent pixels, measured when the image is rendered at 100%.
-
screenTop
andscreenLeft
are the amount of pixels from edge of image to edge device screen. -
screenWidth
andscreenHeight
are the pixel dimensions of the device screen. -
frameWidth
andframeHeight
are the pixel dimensions of the entire frame. This will generally match your image size and represents how big the frame will be rendered on your screen, when at 100% size.
-
- The URLs are absolute paths to the device frame image.
- If the path starts with
/
its relative to the root of your website. The images can be hosted along with your docc-archive or on a remote server. This is the same concept as providing your own custom icons.
- If the path starts with
{
"theme": {
"device-frames": {
"custom-device": {
"screenTop": 27,
"screenLeft": 27,
"screenWidth": 655,
"screenHeight": 490,
"frameWidth": 708,
"frameHeight": 543,
"lightUrl": "/img/device-frames/custom-device.png",
"darkUrl": "/img/device-frames/custom-device~dark.png",
}
}
}
}
Usage:
@Video(
source: "video.mp4",
deviceFrame: "custom-device",
deviceFrameCrop: topHalf,
)