Options
All
  • Public
  • Public/Protected
  • All
Menu

Class LengthEdges<All, Top, Left, Right, Bottom, TopLeft, TopRight, BottomLeft, BottomRight>

A base class that can be used to create mixin aliases for styles that have 'sides', such as borderWidth, padding and margin. To use the base class five ViewStyle interfaces need to be created; one for each side and one that represents all sides:

example
Style Interfaces ```ts import { ViewStyle } from 'react-native'; export interface ITop extends ViewStyle { borderTopWidth: number; } export interface ILeft extends ViewStyle { borderLeftWidth: number; } export interface IRight extends ViewStyle { borderRightWidth: number; } export interface IBottom extends ViewStyle { borderBottomWidth: number; } export interface IAll extends ViewStyle { borderWidth: number; } ``` A function must then be created that can convert the side and value into a style mixin:
example
Example Conversion function ```ts import { LengthEdgesEdge } from '@ef-carbon/react-native-style'; function convert(side: LengthEdgesEdge, value: number): IAll | ITop | ILeft | IRight | IBottom { switch (side) { case 'all': return { borderWidth: Math.max(StyleSheet.hairlineWidth, value) }; case 'top': return { borderTopWidth: Math.max(StyleSheet.hairlineWidth, value) }; case 'left': return { borderLeftWidth: Math.max(StyleSheet.hairlineWidth, value) }; case 'right': return { borderRightWidth: Math.max(StyleSheet.hairlineWidth, value) }; case 'bottom': return { borderBottomWidth: Math.max(StyleSheet.hairlineWidth, value) }; default: return assertNever(side); } } ``` Then the base class can be extended:
example
Derived class ```ts import { LengthEdges } from '@ef-carbon/react-native-style'; export interface IBorderWidthEdgesOptions { edges: ILength; } export class BorderWidthEdges extends LengthEdges implements IEdges { constructor({ edges }: IBorderWidthEdgesOptions) { super({ length: edges, convert }); } } ```

Type parameters

  • All: ViewStyle

  • Top: ViewStyle

  • Left: ViewStyle

  • Right: ViewStyle

  • Bottom: ViewStyle

  • TopLeft: ViewStyle

  • TopRight: ViewStyle

  • BottomLeft: ViewStyle

  • BottomRight: ViewStyle

Hierarchy

Implements

  • ILengthEdges<All, Top, Left, Right, Bottom, TopLeft, TopRight, BottomLeft, BottomRight>

Index

Constructors

constructor

  • new LengthEdges(__namedParameters: object): LengthEdges

Properties

all

all: Readonly<ILength<All>>

bottom

bottom: Readonly<ILength<Bottom>>

bottomLeft

bottomLeft: Readonly<ILength<BottomLeft>>

bottomRight

bottomRight: Readonly<ILength<BottomRight>>

left

left: Readonly<ILength<Left>>

right

right: Readonly<ILength<Right>>

top

top: Readonly<ILength<Top>>

topLeft

topLeft: Readonly<ILength<TopLeft>>

topRight

topRight: Readonly<ILength<TopRight>>

Accessors

huge

  • get huge(): All

large

  • get large(): All

larger

  • get larger(): All

largest

  • get largest(): All

normal

  • get normal(): All

small

  • get small(): All

smaller

  • get smaller(): All

smallest

  • get smallest(): All

tiny

  • get tiny(): All