Skip to content

padding

The padding function sets the inner spacing of a component to create appropriate spacing between content and boundaries. You can specify horizontal (x), vertical (y), and individual direction (top, right, bottom, left) spacing using numbers. You can apply the same value to all directions by entering a number, or set individual values for each direction. There are also presets for commonly used values for easy application.

Signature

typescript
padding: BoxSpacing;

Parameter

  • optionrequired · BoxSpacingOption

    The option value to specify inner spacing. If you enter a number, it applies the same value to all directions,

or you can set individual values for each direction.

Property

  • xrequired · (value: number) => ViewStyle

    Returns a style object that sets the inner spacing of the component's horizontal direction (left and right) by the input number. The returned object is passed to the component's style property to apply the spacing.

  • x4required · ViewStyle

    A style object that applies 4px inner spacing in the horizontal direction

  • x8required · ViewStyle

    A style object that applies 8px inner spacing in the horizontal direction

  • x12required · ViewStyle

    A style object that applies 12px inner spacing in the horizontal direction

  • x16required · ViewStyle

    A style object that applies 16px inner spacing in the horizontal direction

  • x24required · ViewStyle

    A style object that applies 24px inner spacing in the horizontal direction

  • x32required · ViewStyle

    A style object that applies 32px inner spacing in the horizontal direction

  • yrequired · (value: number) => ViewStyle

    Returns a style object that sets the inner spacing of the component's vertical direction (top and bottom) by the input number. The returned object is passed to the component's style property to apply the spacing.

  • y4required · ViewStyle

    A style object that applies 4px inner spacing in the vertical direction

  • y8required · ViewStyle

    A style object that applies 8px inner spacing in the vertical direction

  • y12required · ViewStyle

    A style object that applies 12px inner spacing in the vertical direction

  • y16required · ViewStyle

    A style object that applies 16px inner spacing in the vertical direction

  • y24required · ViewStyle

    A style object that applies 24px inner spacing in the vertical direction

  • y32required · ViewStyle

    A style object that applies 32px inner spacing in the vertical direction

  • toprequired · (value: number) => ViewStyle

    Returns a style object that sets the inner spacing of the component's top direction by the input number. The returned object is passed to the component's style property to apply the spacing.

  • top4required · ViewStyle

    A style object that applies 4px inner spacing to the top

  • top8required · ViewStyle

    A style object that applies 8px inner spacing to the top

  • top12required · ViewStyle

    A style object that applies 12px inner spacing to the top

  • top16required · ViewStyle

    A style object that applies 16px inner spacing to the top

  • top24required · ViewStyle

    A style object that applies 24px inner spacing to the top

  • top32required · ViewStyle

    A style object that applies 32px inner spacing to the top

  • rightrequired · (value: number) => ViewStyle

    Returns a style object that sets the inner spacing of the component's right direction by the input number. The returned object is passed to the component's style property to apply the spacing.

  • right4required · ViewStyle

    A style object that applies 4px inner spacing to the right

  • right8required · ViewStyle

    A style object that applies 8px inner spacing to the right

  • right12required · ViewStyle

    A style object that applies 12px inner spacing to the right

  • right16required · ViewStyle

    A style object that applies 16px inner spacing to the right

  • right24required · ViewStyle

    A style object that applies 24px inner spacing to the right

  • right32required · ViewStyle

    A style object that applies 32px inner spacing to the right

  • bottomrequired · (value: number) => ViewStyle

    Returns a style object that sets the inner spacing of the component's bottom direction by the input number. The returned object is passed to the component's style property to apply the spacing.

  • bottom4required · ViewStyle

    A style object that applies 4px inner spacing to the bottom

  • bottom8required · ViewStyle

    A style object that applies 8px inner spacing to the bottom

  • bottom12required · ViewStyle

    A style object that applies 12px inner spacing to the bottom

  • bottom16required · ViewStyle

    A style object that applies 16px inner spacing to the bottom

  • bottom24required · ViewStyle

    A style object that applies 24px inner spacing to the bottom

  • bottom32required · ViewStyle

    A style object that applies 32px inner spacing to the bottom

  • leftrequired · (value: number) => ViewStyle

    Returns a style object that sets the inner spacing of the component's left direction by the input number. The returned object is passed to the component's style property to apply the spacing.

  • left4required · ViewStyle

    A style object that applies 4px inner spacing to the left

  • left8required · ViewStyle

    A style object that applies 8px inner spacing to the left

  • left12required · ViewStyle

    A style object that applies 12px inner spacing to the left

  • left16required · ViewStyle

    A style object that applies 16px inner spacing to the left

  • left24required · ViewStyle

    A style object that applies 24px inner spacing to the left

  • left32required · ViewStyle

    A style object that applies 32px inner spacing to the left

Example

Example of applying 8px inner spacing in horizontal and vertical directions, and 100px spacing in the bottom direction

tsx
import { padding } from '@granite-js/react-native';
import { View } from 'react-native';

function Component() {
  return (
    <View>
      <View style={padding.x8}>
        <Text>Has horizontal spacing</Text>
      </View>
      <View style={padding.y8}>
        <Text>Has vertical spacing</Text>
      </View>
      <View style={padding.bottom(100)}>
        <Text>Has 100px spacing at the bottom</Text>
      </View>
    </View>
  );
}