# View
View is a generic container component. Its contents will always be their “natural” size, so this component can be useful in layout components (like `Grid`, `BlockStack`, `InlineStack`) that would otherwise stretch their children to fit.
```tsx
import {
reactExtension,
View,
} from '@shopify/ui-extensions-react/checkout';
export default reactExtension(
'purchase.checkout.block.render',
() => ,
);
function Extension() {
return (
View
);
}
```
```js
import {extension, View} from '@shopify/ui-extensions/checkout';
export default extension('purchase.checkout.block.render', (root) => {
const view = root.createComponent(
View,
{border: 'base', padding: 'base'},
'View',
);
root.appendChild(view);
});
```
## ViewProps
### ViewProps
### display
value: `Display`
- Display: 'block' | 'inline'
Changes the display of the View.
`inline` follows the direction of words in a sentence based on the document’s writing mode.
`block` follows the direction of paragraphs based on the document’s writing mode.
### id
value: `string`
A unique identifier for the View.
### opacity
value: `Opacity`
- Opacity: 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 | 90
Sets the opacity of the View. The opacity will be applied to the background as well as all
the children of the View. Use carefully as this could decrease the contrast ratio between
the background and foreground elements, resulting in unreadable and inaccessible text.
### accessibilityLabel
value: `string`
A label that describes the purpose or contents of the element. When set,
it will be announced to buyers using assistive technologies and will
provide them with more context.
### accessibilityRole
value: `ViewLikeAccessibilityRole`
- ViewLikeAccessibilityRole: NonPresentationalAccessibilityRole | [NonPresentationalAccessibilityRole, NonPresentationalAccessibilityRole]
Sets the semantic meaning of the component’s content. When set,
the role will be used by assistive technologies to help buyers
navigate the page.
For example:
- In an HTML host a `['listItem', 'separator']` tuple will render: `
`
- In an HTML host a `listItem` string will render: ``
### position
value: `MaybeResponsiveConditionalStyle`
- MaybeResponsiveConditionalStyle: T | ConditionalStyle
- ConditionalStyle: export interface ConditionalStyle<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The default value applied when none of the conditional values
* specified in `conditionals` are met.
*/
default?: T;
/**
* An array of conditional values.
*/
conditionals: ConditionalValue[];
}
- Position: {
/**
* Changes how the View is positioned. For setting the position, only properties
* that set the offset on a different axis can be set simultaneously. This means
* that these combinations are not allowed:
*
* ```
* { blockStart, blockEnd }
* ```
*
* ```
* { inlineStart, inlineEnd }
* ```
*
* @defaultValue 'relative'
*/
type?: PositionType;
} & PositionCoordinates
Changes how the View is positioned.
### translate
value: `MaybeResponsiveConditionalStyle`
- MaybeResponsiveConditionalStyle: T | ConditionalStyle
- ConditionalStyle: export interface ConditionalStyle<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The default value applied when none of the conditional values
* specified in `conditionals` are met.
*/
default?: T;
/**
* An array of conditional values.
*/
conditionals: ConditionalValue[];
}
- Translate: export interface Translate {
/**
* Adjust the translation on the cross axis.
*
* A percentage value refers to the block size of the View.
*/
block?: number | `${number}%`;
/**
* Adjust the translation on the main axis.
*
* A percentage value refers to the inline size of the View.
*/
inline?: number | `${number}%`;
}
Specifies a two-dimensional translation of the View.
### blockAlignment
value: `MaybeResponsiveConditionalStyle<
Extract
>`
- MaybeResponsiveConditionalStyle: T | ConditionalStyle
- ConditionalStyle: export interface ConditionalStyle<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The default value applied when none of the conditional values
* specified in `conditionals` are met.
*/
default?: T;
/**
* An array of conditional values.
*/
conditionals: ConditionalValue[];
}
- BlockAlignment: Alignment | 'baseline'
- Alignment: 'start' | 'center' | 'end'
Position children along the cross axis
### inlineAlignment
value: `MaybeResponsiveConditionalStyle`
- MaybeResponsiveConditionalStyle: T | ConditionalStyle
- ConditionalStyle: export interface ConditionalStyle<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The default value applied when none of the conditional values
* specified in `conditionals` are met.
*/
default?: T;
/**
* An array of conditional values.
*/
conditionals: ConditionalValue[];
}
- Alignment: 'start' | 'center' | 'end'
- InlineAlignment: 'start' | 'center' | 'end'
Position children along the main axis
### inlineSize
value: `MaybeResponsiveConditionalStyle<'fill'>`
- MaybeResponsiveConditionalStyle: T | ConditionalStyle
- ConditionalStyle: export interface ConditionalStyle<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The default value applied when none of the conditional values
* specified in `conditionals` are met.
*/
default?: T;
/**
* An array of conditional values.
*/
conditionals: ConditionalValue[];
}
Adjust the inline size.
`fill`: takes all the available space.
### overflow
value: `"hidden" | "visible"`
Sets the overflow behavior of the element.
`hidden`: clips the content when it is larger than the element’s container.
The element will not be scrollable and the users will not be able
to access the clipped content by dragging or using a scroll wheel.
`visible`: the content that extends beyond the element’s container is visible.
### border
value: `MaybeResponsiveConditionalStyle>`
- MaybeResponsiveConditionalStyle: T | ConditionalStyle
- ConditionalStyle: export interface ConditionalStyle<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The default value applied when none of the conditional values
* specified in `conditionals` are met.
*/
default?: T;
/**
* An array of conditional values.
*/
conditionals: ConditionalValue[];
}
- MaybeShorthandProperty: T | ShorthandProperty
- ShorthandProperty: [T, T] | [T, T, T, T]
- BorderStyle: 'base' | 'dotted' | 'none'
Adjust the border style.
To shorten the code, it is possible to specify all the border style properties in one property.
For example:
- `base` means blockStart, inlineEnd, blockEnd and inlineStart border styles are `base`
- `['base', 'none']` means blockStart and blockEnd border styles are `base`, inlineStart and inlineEnd border styles are `none`
- `['base', 'none', 'dotted', 'base']` means blockStart border style is `base`, inlineEnd border style is `none`, blockEnd border style is `dotted` and blockStart border style is `base`
### borderWidth
value: `MaybeResponsiveConditionalStyle<
MaybeShorthandProperty
>`
- MaybeResponsiveConditionalStyle: T | ConditionalStyle
- ConditionalStyle: export interface ConditionalStyle<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The default value applied when none of the conditional values
* specified in `conditionals` are met.
*/
default?: T;
/**
* An array of conditional values.
*/
conditionals: ConditionalValue[];
}
- MaybeShorthandProperty: T | ShorthandProperty
- ShorthandProperty: [T, T] | [T, T, T, T]
- BorderWidth: 'base' | 'medium'
Adjust the border width.
To shorten the code, it is possible to specify all the border width properties in one property.
For example:
- `base` means blockStart, inlineEnd, blockEnd and inlineStart border widths are `base`
- `['base', 'medium']` means blockStart and blockEnd border widths are `base`, inlineStart and inlineEnd border widths are `medium`
- `['base', 'medium', 'medium', 'base']` means blockStart border width is `base`, inlineEnd border width is `medium`, blockEnd border width is `medium` and blockStart border width is `base`
### borderRadius
value: `MaybeResponsiveConditionalStyle<
MaybeShorthandProperty
>`
- MaybeResponsiveConditionalStyle: T | ConditionalStyle
- ConditionalStyle: export interface ConditionalStyle<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The default value applied when none of the conditional values
* specified in `conditionals` are met.
*/
default?: T;
/**
* An array of conditional values.
*/
conditionals: ConditionalValue[];
}
- MaybeShorthandProperty: T | ShorthandProperty
- ShorthandProperty: [T, T] | [T, T, T, T]
- CornerRadius: 'base' | 'small' | 'large' | 'fullyRounded' | 'none' | CornerRadiusDeprecated
### cornerRadius
value: `MaybeResponsiveConditionalStyle<
MaybeShorthandProperty
>`
- MaybeResponsiveConditionalStyle: T | ConditionalStyle
- ConditionalStyle: export interface ConditionalStyle<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The default value applied when none of the conditional values
* specified in `conditionals` are met.
*/
default?: T;
/**
* An array of conditional values.
*/
conditionals: ConditionalValue[];
}
- MaybeShorthandProperty: T | ShorthandProperty
- ShorthandProperty: [T, T] | [T, T, T, T]
- CornerRadius: 'base' | 'small' | 'large' | 'fullyRounded' | 'none' | CornerRadiusDeprecated
Adjust the corner radius.
Provide a single value to apply the same corner radius to all four corners, two values to apply different corner radii to opposing corners, or four values to apply different corner radii to each individual corner.
For example:
- `base` means all 4 corner radii are `base`
- `['base', 'none']` means the StartStart and EndEnd corner radii are `base`, StartEnd and EndStart corner radii are `none`.
When the context’s language direction is left to right, StartStart and EndEnd corners are the top left and bottom right corners
while StartEnd and EndStart corners are the top right and bottom left corners.
- `['base', 'none', 'small', 'base']` means StartStart corner radius is `base`, StartEnd corner radius is `none`, EndEnd corner radius is `small` and EndStart corner radius is `base`
A `borderRadius` alias is available for this property. When both are specified, `cornerRadius` takes precedence.
### maxBlockSize
value: `MaybeResponsiveConditionalStyle<
number | `${number}%` | 'fill'
>`
- MaybeResponsiveConditionalStyle: T | ConditionalStyle
- ConditionalStyle: export interface ConditionalStyle<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The default value applied when none of the conditional values
* specified in `conditionals` are met.
*/
default?: T;
/**
* An array of conditional values.
*/
conditionals: ConditionalValue[];
}
Adjust the maximum block size.
`number`: size in pixels.
`` `${number}%` ``: size in percentages.
`fill`: takes all the available space.
See [MDN explanation of maxBlockSize](https://developer.mozilla.org/en-US/docs/Web/CSS/max-block-size).
### maxInlineSize
value: `MaybeResponsiveConditionalStyle<
number | `${number}%` | 'fill'
>`
- MaybeResponsiveConditionalStyle: T | ConditionalStyle
- ConditionalStyle: export interface ConditionalStyle<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The default value applied when none of the conditional values
* specified in `conditionals` are met.
*/
default?: T;
/**
* An array of conditional values.
*/
conditionals: ConditionalValue[];
}
Adjust the maximum inline size.
`number`: size in pixels.
`` `${number}%` ``: size in percentages.
`fill`: takes all the available space.
See [MDN explanation of maxInlineSize](https://developer.mozilla.org/en-US/docs/Web/CSS/max-inline-size).
### minInlineSize
value: `MaybeResponsiveConditionalStyle<
number | `${number}%` | 'fill'
>`
- MaybeResponsiveConditionalStyle: T | ConditionalStyle
- ConditionalStyle: export interface ConditionalStyle<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The default value applied when none of the conditional values
* specified in `conditionals` are met.
*/
default?: T;
/**
* An array of conditional values.
*/
conditionals: ConditionalValue[];
}
Adjust the minimum inline size.
`number`: size in pixels.
`` `${number}%` ``: size in percentages.
`fill`: takes all the available space.\
See [MDN explanation of minInlineSize](https://developer.mozilla.org/en-US/docs/Web/CSS/min-inline-size).
### minBlockSize
value: `MaybeResponsiveConditionalStyle<
number | `${number}%` | 'fill'
>`
- MaybeResponsiveConditionalStyle: T | ConditionalStyle
- ConditionalStyle: export interface ConditionalStyle<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The default value applied when none of the conditional values
* specified in `conditionals` are met.
*/
default?: T;
/**
* An array of conditional values.
*/
conditionals: ConditionalValue[];
}
Adjust the block size.
`number`: size in pixels.
`` `${number}%` ``: size in percentages.
`fill`: takes all the available space.
See [MDN explanation of minBlockSize](https://developer.mozilla.org/en-US/docs/Web/CSS/min-block-size).
### padding
value: `MaybeResponsiveConditionalStyle>`
- MaybeResponsiveConditionalStyle: T | ConditionalStyle
- ConditionalStyle: export interface ConditionalStyle<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The default value applied when none of the conditional values
* specified in `conditionals` are met.
*/
default?: T;
/**
* An array of conditional values.
*/
conditionals: ConditionalValue[];
}
- MaybeShorthandProperty: T | ShorthandProperty
- ShorthandProperty: [T, T] | [T, T, T, T]
- Spacing: 'none' | 'extraTight' | 'tight' | 'base' | 'loose' | 'extraLoose'
Adjust the padding.
To shorten the code, it is possible to specify all the padding properties in one property.
Examples:
- `base` means blockStart, inlineEnd, blockEnd and inlineStart paddings are `base`
- [`base`, `none`] means blockStart and blockEnd paddings are `base`, inlineStart and inlineEnd paddings are `none`
- [`base`, `none`, `loose`, `tight`] means blockStart padding is `base`, inlineEnd padding is `none`, blockEnd padding is `loose` and blockStart padding is `tight`
### visibility
value: `Visibility`
- Visibility: 'hidden'
Changes the visibility of the element.
`hidden` visually hides the component while keeping it accessible
to assistive technology, such as screen readers.
Hidden elements don't take any visual space contrary to CSS visibility: hidden;
### accessibilityVisibility
value: `AccessibilityVisibility`
- Visibility: 'hidden'
- AccessibilityVisibility: 'hidden'
Changes the visibility of the element to assistive technologies.
`hidden` hides the component from assistive technology (for example,
a screen reader) but remains visually visible.
### background
value: `MaybeConditionalStyle`
- ConditionalStyle: export interface ConditionalStyle<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The default value applied when none of the conditional values
* specified in `conditionals` are met.
*/
default?: T;
/**
* An array of conditional values.
*/
conditionals: ConditionalValue[];
}
- MaybeConditionalStyle: T | ConditionalStyle
- Background: 'transparent' | 'base' | 'subdued'
Adjust the background.
### ConditionalStyle
### default
value: `T`
The default value applied when none of the conditional values
specified in `conditionals` are met.
### conditionals
value: `ConditionalValue[]`
- ConditionalValue: export interface ConditionalValue<
T,
AcceptedConditions extends BaseConditions = Conditions,
> {
/**
* The conditions that must be met for the value to be applied. At least one
* condition must be specified.
*/
conditions: AcceptedConditions;
/**
* The value that will be applied if the conditions are met.
*/
value: T;
}
An array of conditional values.
### ConditionalValue
### conditions
value: `AcceptedConditions`
The conditions that must be met for the value to be applied. At least one
condition must be specified.
### value
value: `T`
The value that will be applied if the conditions are met.
### ViewportSizeCondition
### viewportInlineSize
value: `{ min: ViewportInlineSize; }`
- ViewportInlineSize: 'small' | 'medium' | 'large'
### Translate
### block
value: `number | `${number}%``
Adjust the translation on the cross axis.
A percentage value refers to the block size of the View.
### inline
value: `number | `${number}%``
Adjust the translation on the main axis.
A percentage value refers to the inline size of the View.