Cutout Component
General Information
- Cutouts are generated through a svelte
Cutoutcomponent, which can be imported by including the following line in the file's script tag:
import Cutout from '$lib/components/Cutout.svelte'; - The cutouts are applied by adding a composite mask to the target container. The mask itself
is an url-encoded SVG image which gets generated automatically by the
Cutoutcomponent based on the desired parameters, including its corresponding mask size, position and composition values. - Cutouts can be applied to all four corners of the target container. Said corners are
referred to as the
topLeft,topRight,bottomLeftandbottomRightcorners. - The
Cutoutcomponent has three parameters through which the cutout can be configured.config: An object that defines the cutouts that are to be applied. A cutout definition can be provided for one of the four corners of the container by using its name as the key in the object. Furthermore, each object can have multiple cutouts defined as long as they are on different corners. A cutout definition is defined as follows:- Value
'small'applies a cutout that corresponds to a half by half-block circle. - Value
'button'renders a cutout that fits a default-sized button. - An object can be provided to generate a cutout with custom sizing. The object will
need to provide the
widthandheightof the cutout in half-blocks (excluding padding). Optionally, theradiusStart,radiusInner,radiusEndandpaddingof the cutout can be defined in half-blocks as well. Note thatradiusStartis the radius of the curve connected to the horizontal border andradiusEndis the radius of the curve bordering the vertical border.
- Value
useGrid: Defines whether the cutout should be placed by grid rows/columns or through absolute positioning (defaulttrue). Additionally, the cutout element will copy its parent's grid layout if set to true. Note that an explicit height needs to be set throughheightorgrid-template-columnsfor the grid positioning to work correctly. The inclusion of positionrelativeis required on the parent node in case no grid is used.excludeInMobile: Specifies whether the cutout should be disabled in mobile mode (defaultfalse) by setting all mask properties toinitial.
- The cutout defined through the
Cutoutcomponent will be applied to all elements contained within its tags. Therefore, an element needs to be placed outside of theCutouttags if you need said element to appear over a cutout area.
Code Examples
<Cutout config={{ topRight: 'small' }}>
<div class='background'></div>
</Cutout><Cutout config={{ bottomRight: 'button' }}>
<div class='background'></div>
</Cutout><Cutout config={
{
topLeft: {
width: 11, height: 4
},
bottomRight: {
width: 3, height: 3, radiusInner: 0.5
}
}
}>
<div class='background'></div>
</Cutout><Cutout config={
{
topRight: 'small',
bottomRight: 'button',
topLeft: {
width: 8, height: 7, radiusInner: 2,
radiusStart: 3, radiusEnd: 1
}
}
}>
<div class='background'></div>
</Cutout>