0.9.0 • Published 1 month ago

@fluentui-react-native/merge-props v0.9.0

Weekly downloads
40
License
MIT
Repository
github
Last release
1 month ago

@fluentui-react-native/merge-props

Utilities for merging styles and props (which contain styles)

Merging Props

The mergeProps routine handles merging props together. Generally this is a standard per property merge identical to the behavior of Object.assign with the following two exceptions:

  • Objects under props.style will be merged using mergeStyle above, including caching the resolved styles
  • Strings contained in props.className will be joined together using spaces as a delimiter.

Merging Styles

Styles are defined using the standard react-native pattern and will be merged in a way that maintains object identity where possible.

StyleProp

This is a copy of the StyleProp definition from react-native. This is copied primarily in the case where it is used in web code where adding a dependency on the react-native package itself is not desireable.

The StyleProp pattern itself is allows a style to be provided as a style or a recursive array of styles. So the following pattern is allowed:

props = {
  style: [{ ...style1 }, [{ ...style2 }, { ...style3 }, [{ ...style4 }]], { ...style5 }],
};

In this model merging styles can be effectively deferred by the following:

const styleToMerge = { ...values };
props.style = [props.style, styleToMerge];

mergeStyles

This routine merges one or more react-native styles together. The inputs are styles in the StyleProp format referenced above. The various input styles will be flattened and merged together to produce a single non-flattened output style.

function mergeStyles<T>(...styles: StyleProp<T>[]): T;

This routine has a built-in caching layer that will attempt to ensure that object identity remains consistent. This means that style A + style B, where the references to A and B are the same, will always produce object C, where the reference will also be the same.

0.9.0

1 month ago

0.8.1

3 months ago

0.8.0

6 months ago

0.7.1

10 months ago

0.7.0

11 months ago

0.6.0

12 months ago

0.5.3

1 year ago

0.5.2

1 year ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

3 years ago

0.3.5

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.0

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago