This is a helper for authoring conditional values for property styles. Write complex conditional styles based on one or more conditions, such as viewport sizes and interactive states, in a concise and expressive way.
import {
reactExtension,
Style,
View,
} from '@shopify/ui-extensions-react/checkout';
export default reactExtension('purchase.checkout.block.render', () => (
<Extension />
));
function Extension() {
return (
<View
maxInlineSize={Style.default(200)
.when({viewportInlineSize: {min: 'small'}}, 300)
.when({viewportInlineSize: {min: 'medium'}}, 400)
.when({viewportInlineSize: {min: 'large'}}, 800)}
>
Responsive Content
</View>
);
}
import {Style, View, extension} from '@shopify/ui-extensions/checkout';
export default extension('purchase.checkout.block.render', (root) => {
const view = root.createComponent(
View,
{
border: 'base',
padding: 'base',
maxInlineSize: Style.default(200)
.when({viewportInlineSize: {min: 'small'}}, 300)
.when({viewportInlineSize: {min: 'medium'}}, 400)
.when({viewportInlineSize: {min: 'large'}}, 800),
},
'Responsive Content',
);
root.appendChild(view);
});
Sets an optional default value to use when no other condition is met.
Adjusts the style based on different conditions. All conditions, expressed as a literal object, must be met for the associated value to be applied. The `when` method can be chained together to build more complex styles.
An array of conditional values.
The default value applied when none of the conditional values specified in `conditionals` are met.
The conditions that must be met for the value to be applied. At least one condition must be specified.
The value that will be applied if the conditions are met.
'extraSmall' | 'small' | 'medium' | 'large'
This is a helper for authoring conditional values for property styles. Write complex conditional styles based on one or more conditions, such as viewport sizes and interactive states, in a concise and expressive way.
Default styling can be combined with specific conditions. In this example, the Grid’s children will be stacked by default and side by side on viewports above the <code>small</code> breakpoint.
<Grid
columns={Style.default('fill').when({viewportInlineSize: {min: 'small'}}, [
'30%',
'70%',
])}
>
<View>Content</View>
<View>Content</View>
</Grid>;
<Grid
columns={Style.default('fill').when({viewportInlineSize: {min: 'small'}}, [
'30%',
'70%',
])}
>
<View>Content</View>
<View>Content</View>
</Grid>;
Using simple conditional styling enables you to specify a styling change when a condition is met. In this example, the View’s padding will be <code>loose</code> on hover.
<Pressable
onPress={() => alert('press')}
border={Style.default(['base', 'dotted']).when(
{viewportInlineSize: {min: 'small'}},
['base', 'dotted', 'none', 'base'],
)}
>
Content
</Pressable>;
<Pressable
onPress={() => alert('press')}
border={Style.default(['base', 'dotted']).when(
{viewportInlineSize: {min: 'small'}},
['base', 'dotted', 'none', 'base'],
)}
>
Content
</Pressable>;
Using the `display` property with conditional styles enables you to hide content for certain viewport sizes. In this example, the View will be hidden on small and above screen sizes.
<View
display={Style.default('auto').when(
{viewportInlineSize: {min: 'small'}},
'none',
)}
>
Content
</View>;
<View
display={Style.default('auto').when(
{viewportInlineSize: {min: 'small'}},
'none',
)}
>
Content
</View>;