bootstrap-rn 0.3.4 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/lib/commonjs/components/Image.js.map +1 -1
  2. package/lib/commonjs/components/ImageBackground.js.map +1 -1
  3. package/lib/commonjs/components/Text.js.map +1 -1
  4. package/lib/commonjs/components/dropdown/DropdownMenu.js.map +1 -1
  5. package/lib/commonjs/components/forms/RadioGroup.js.map +1 -1
  6. package/lib/commonjs/components/forms/internals/PickerNative.js.map +1 -1
  7. package/lib/commonjs/components/modal/Modal.js +1 -1
  8. package/lib/commonjs/components/modal/Modal.js.map +1 -1
  9. package/lib/commonjs/components/modal/ModalBody.js +1 -1
  10. package/lib/commonjs/components/modal/ModalBody.js.map +1 -1
  11. package/lib/commonjs/components/modal/ModalContext.js.map +1 -1
  12. package/lib/commonjs/components/nav/Nav.js.map +1 -1
  13. package/lib/commonjs/components/nav/NavContext.js.map +1 -1
  14. package/lib/commonjs/components/nav/TabContext.js.map +1 -1
  15. package/lib/commonjs/components/navbar/NavbarContext.js.map +1 -1
  16. package/lib/commonjs/components/offcanvas/OffcanvasBody.js.map +1 -1
  17. package/lib/commonjs/components/offcanvas/OffcanvasContext.js.map +1 -1
  18. package/lib/commonjs/components/popover/injectPopover.js.map +1 -1
  19. package/lib/commonjs/components/toasts/ToastContainer.js +3 -1
  20. package/lib/commonjs/components/toasts/ToastContainer.js.map +1 -1
  21. package/lib/commonjs/components/tooltip/injectTooltip.js +0 -3
  22. package/lib/commonjs/components/tooltip/injectTooltip.js.map +1 -1
  23. package/lib/commonjs/index.d.ts +47 -8
  24. package/lib/commonjs/index.js +0 -56
  25. package/lib/commonjs/index.js.map +1 -1
  26. package/lib/commonjs/style/StyleSheet.js +4 -2
  27. package/lib/commonjs/style/StyleSheet.js.map +1 -1
  28. package/lib/commonjs/style/makeUtilities.js.map +1 -1
  29. package/lib/commonjs/types.d.ts +6 -3
  30. package/lib/module/components/Image.js.map +1 -1
  31. package/lib/module/components/ImageBackground.js.map +1 -1
  32. package/lib/module/components/Text.js.map +1 -1
  33. package/lib/module/components/dropdown/DropdownMenu.js.map +1 -1
  34. package/lib/module/components/forms/RadioGroup.js.map +1 -1
  35. package/lib/module/components/forms/internals/PickerNative.js.map +1 -1
  36. package/lib/module/components/modal/Modal.js +1 -1
  37. package/lib/module/components/modal/Modal.js.map +1 -1
  38. package/lib/module/components/modal/ModalBody.js +1 -1
  39. package/lib/module/components/modal/ModalBody.js.map +1 -1
  40. package/lib/module/components/modal/ModalContext.js.map +1 -1
  41. package/lib/module/components/nav/Nav.js.map +1 -1
  42. package/lib/module/components/nav/NavContext.js.map +1 -1
  43. package/lib/module/components/nav/TabContext.js.map +1 -1
  44. package/lib/module/components/navbar/NavbarContext.js.map +1 -1
  45. package/lib/module/components/offcanvas/OffcanvasBody.js.map +1 -1
  46. package/lib/module/components/offcanvas/OffcanvasContext.js.map +1 -1
  47. package/lib/module/components/popover/injectPopover.js.map +1 -1
  48. package/lib/module/components/toasts/ToastContainer.js +3 -1
  49. package/lib/module/components/toasts/ToastContainer.js.map +1 -1
  50. package/lib/module/components/tooltip/injectTooltip.js +0 -3
  51. package/lib/module/components/tooltip/injectTooltip.js.map +1 -1
  52. package/lib/module/index.d.ts +47 -8
  53. package/lib/module/index.js +0 -7
  54. package/lib/module/index.js.map +1 -1
  55. package/lib/module/style/StyleSheet.js +4 -2
  56. package/lib/module/style/StyleSheet.js.map +1 -1
  57. package/lib/module/style/makeUtilities.js.map +1 -1
  58. package/lib/module/types.d.ts +6 -3
  59. package/lib/types/components/Image.d.ts.map +1 -1
  60. package/lib/types/components/ImageBackground.d.ts.map +1 -1
  61. package/lib/types/components/Text.d.ts +1 -1
  62. package/lib/types/components/Text.d.ts.map +1 -1
  63. package/lib/types/components/dropdown/Dropdown.d.ts +2 -11
  64. package/lib/types/components/dropdown/Dropdown.d.ts.map +1 -1
  65. package/lib/types/components/dropdown/DropdownContext.d.ts +2 -2
  66. package/lib/types/components/dropdown/DropdownContext.d.ts.map +1 -1
  67. package/lib/types/components/dropdown/DropdownMenu.d.ts +2 -2
  68. package/lib/types/components/dropdown/DropdownMenu.d.ts.map +1 -1
  69. package/lib/types/components/dropdown/DropdownToggle.d.ts +2 -2
  70. package/lib/types/components/dropdown/DropdownToggle.d.ts.map +1 -1
  71. package/lib/types/components/forms/Picker.d.ts +4 -4
  72. package/lib/types/components/forms/Picker.d.ts.map +1 -1
  73. package/lib/types/components/forms/PickerItem.d.ts +1 -1
  74. package/lib/types/components/forms/PickerItem.d.ts.map +1 -1
  75. package/lib/types/components/forms/Radio.d.ts +1 -1
  76. package/lib/types/components/forms/Radio.d.ts.map +1 -1
  77. package/lib/types/components/forms/RadioContext.d.ts +2 -2
  78. package/lib/types/components/forms/RadioContext.d.ts.map +1 -1
  79. package/lib/types/components/forms/RadioGroup.d.ts +2 -2
  80. package/lib/types/components/forms/RadioGroup.d.ts.map +1 -1
  81. package/lib/types/components/forms/internals/PickerNative.d.ts.map +1 -1
  82. package/lib/types/components/forms/internals/PickerNativeContext.d.ts +2 -2
  83. package/lib/types/components/forms/internals/PickerNativeContext.d.ts.map +1 -1
  84. package/lib/types/components/forms/internals/PickerNativeItem.d.ts +1 -1
  85. package/lib/types/components/forms/internals/PickerNativeItem.d.ts.map +1 -1
  86. package/lib/types/components/forms/internals/PickerWebItem.d.ts +1 -1
  87. package/lib/types/components/forms/internals/PickerWebItem.d.ts.map +1 -1
  88. package/lib/types/components/list-group/ListGroup.d.ts +1 -1
  89. package/lib/types/components/list-group/ListGroupItem.d.ts +13 -1
  90. package/lib/types/components/list-group/ListGroupItem.d.ts.map +1 -1
  91. package/lib/types/components/list-group/ListGroupItemAction.d.ts +2 -2
  92. package/lib/types/components/list-group/ListGroupItemAction.d.ts.map +1 -1
  93. package/lib/types/components/modal/Modal.d.ts +4 -7
  94. package/lib/types/components/modal/Modal.d.ts.map +1 -1
  95. package/lib/types/components/modal/ModalBody.d.ts +3 -6
  96. package/lib/types/components/modal/ModalBody.d.ts.map +1 -1
  97. package/lib/types/components/modal/ModalContext.d.ts +3 -3
  98. package/lib/types/components/modal/ModalContext.d.ts.map +1 -1
  99. package/lib/types/components/nav/Nav.d.ts +1 -3
  100. package/lib/types/components/nav/Nav.d.ts.map +1 -1
  101. package/lib/types/components/nav/NavContext.d.ts +3 -3
  102. package/lib/types/components/nav/NavContext.d.ts.map +1 -1
  103. package/lib/types/components/nav/Tab.d.ts +1 -1
  104. package/lib/types/components/nav/TabContext.d.ts +3 -3
  105. package/lib/types/components/nav/TabContext.d.ts.map +1 -1
  106. package/lib/types/components/navbar/Navbar.d.ts +1 -1
  107. package/lib/types/components/navbar/NavbarBrand.d.ts +2 -2
  108. package/lib/types/components/navbar/NavbarBrand.d.ts.map +1 -1
  109. package/lib/types/components/navbar/NavbarContext.d.ts +2 -2
  110. package/lib/types/components/navbar/NavbarContext.d.ts.map +1 -1
  111. package/lib/types/components/offcanvas/Offcanvas.d.ts +1 -3
  112. package/lib/types/components/offcanvas/Offcanvas.d.ts.map +1 -1
  113. package/lib/types/components/offcanvas/OffcanvasBody.d.ts +3 -4
  114. package/lib/types/components/offcanvas/OffcanvasBody.d.ts.map +1 -1
  115. package/lib/types/components/offcanvas/OffcanvasContext.d.ts +2 -2
  116. package/lib/types/components/offcanvas/OffcanvasContext.d.ts.map +1 -1
  117. package/lib/types/components/popover/injectPopover.d.ts +9 -12
  118. package/lib/types/components/popover/injectPopover.d.ts.map +1 -1
  119. package/lib/types/components/toasts/ToastContainer.d.ts +4 -2
  120. package/lib/types/components/toasts/ToastContainer.d.ts.map +1 -1
  121. package/lib/types/components/tooltip/injectTooltip.d.ts +8 -11
  122. package/lib/types/components/tooltip/injectTooltip.d.ts.map +1 -1
  123. package/lib/types/hooks/useBackground.native.d.ts +3 -1
  124. package/lib/types/hooks/useBackground.native.d.ts.map +1 -1
  125. package/lib/types/index.d.ts +47 -8
  126. package/lib/types/index.d.ts.map +1 -1
  127. package/lib/types/style/StyleSheet.d.ts +2 -3
  128. package/lib/types/style/StyleSheet.d.ts.map +1 -1
  129. package/lib/types/style/createStyle.d.ts +3 -1
  130. package/lib/types/style/createStyle.d.ts.map +1 -1
  131. package/lib/types/style/css.d.ts +3 -1
  132. package/lib/types/style/css.d.ts.map +1 -1
  133. package/lib/types/style/makeUtilities.d.ts +6 -2
  134. package/lib/types/style/makeUtilities.d.ts.map +1 -1
  135. package/lib/types/theme/variables.d.ts +3 -1
  136. package/lib/types/theme/variables.d.ts.map +1 -1
  137. package/lib/types/types.d.ts +6 -3
  138. package/lib/types/types.d.ts.map +1 -1
  139. package/package.json +80 -80
  140. package/src/components/Image.tsx +31 -27
  141. package/src/components/ImageBackground.tsx +48 -46
  142. package/src/components/Text.tsx +119 -117
  143. package/src/components/dropdown/DropdownContext.ts +2 -2
  144. package/src/components/dropdown/DropdownMenu.tsx +127 -125
  145. package/src/components/dropdown/DropdownToggle.ts +2 -2
  146. package/src/components/forms/Picker.tsx +191 -191
  147. package/src/components/forms/PickerItem.tsx +32 -32
  148. package/src/components/forms/Radio.tsx +37 -37
  149. package/src/components/forms/RadioContext.ts +13 -13
  150. package/src/components/forms/RadioGroup.tsx +42 -40
  151. package/src/components/forms/internals/PickerNative.tsx +193 -195
  152. package/src/components/forms/internals/PickerNativeContext.ts +14 -14
  153. package/src/components/forms/internals/PickerNativeItem.tsx +59 -59
  154. package/src/components/forms/internals/PickerWebItem.tsx +36 -36
  155. package/src/components/list-group/ListGroupItemAction.tsx +2 -2
  156. package/src/components/modal/Modal.tsx +234 -233
  157. package/src/components/modal/ModalBody.tsx +52 -56
  158. package/src/components/modal/ModalContext.ts +3 -3
  159. package/src/components/nav/Nav.tsx +4 -4
  160. package/src/components/nav/NavContext.ts +3 -3
  161. package/src/components/nav/TabContext.ts +3 -3
  162. package/src/components/navbar/NavbarBrand.tsx +2 -2
  163. package/src/components/navbar/NavbarContext.ts +2 -2
  164. package/src/components/offcanvas/OffcanvasBody.tsx +64 -66
  165. package/src/components/offcanvas/OffcanvasContext.ts +4 -2
  166. package/src/components/popover/injectPopover.tsx +97 -98
  167. package/src/components/toasts/ToastContainer.tsx +41 -39
  168. package/src/components/tooltip/injectTooltip.tsx +93 -96
  169. package/src/index.ts +242 -211
  170. package/src/style/StyleSheet.ts +149 -138
  171. package/src/style/makeUtilities.ts +79 -76
  172. package/src/types.ts +168 -162
@@ -1,138 +1,149 @@
1
- import { StyleSheet as BaseStyleSheet } from 'react-native';
2
- import type { ExtendedStyle, BaseStyle, ThemeVariables } from '../types';
3
-
4
- type StyleSource = Record<
5
- string,
6
- (theme: object, key: string) => ExtendedStyle | ExtendedStyle
7
- >;
8
-
9
- type NamedExtendedStyles = Record<string, ExtendedStyle>;
10
- type NamedStyles = Record<string, BaseStyle>;
11
-
12
- type StyleSheetDefinition = {
13
- source: StyleSource;
14
- cache: Record<string, NamedExtendedStyles>;
15
- active: NamedExtendedStyles;
16
- };
17
-
18
- let activeKey: string | null = null;
19
-
20
- const themes: Record<string, ThemeVariables> = {};
21
- const sheets: StyleSheetDefinition[] = [];
22
-
23
- const createSheet = (sheet: StyleSheetDefinition): NamedExtendedStyles => {
24
- const theme = themes[activeKey as string];
25
-
26
- const statelessSource: NamedStyles = {};
27
- const statefulSource: NamedExtendedStyles = {};
28
-
29
- // Apply theme to themeable styles.
30
- Object.entries(sheet.source).forEach(([key, style]) => {
31
- // Resolve theme.
32
- const value =
33
- typeof style === 'function' ? style(theme, activeKey as string) : style;
34
-
35
- if (typeof value === 'function') {
36
- statefulSource[key] = value;
37
- } else {
38
- statelessSource[key] = value as BaseStyle;
39
- }
40
- });
41
-
42
- // Wrap stateful and stateless in a proxy, so that we can update the styles on theme change.
43
- // For using Object.assign below we need some additional methods on the proxy that are mentioned here:
44
- // https://stackoverflow.com/questions/43185453/object-assign-and-proxies
45
- // @ts-expect-error proxy is equivalent to NamedExtendedStyles
46
- return new Proxy(
47
- {
48
- keys: Object.keys(sheet.source),
49
- stateless: BaseStyleSheet.create(statelessSource),
50
- stateful: statefulSource,
51
- },
52
- {
53
- get(target, prop: string) {
54
- return target.stateless[prop] || target.stateful[prop] || undefined;
55
- },
56
- ownKeys: (target) => target.keys,
57
- getOwnPropertyDescriptor(target, name: string) {
58
- // eslint-disable-next-line @typescript-eslint/no-this-alias
59
- const proxy = this;
60
-
61
- return {
62
- get value() {
63
- return proxy.get(target, name);
64
- },
65
- configurable: true,
66
- enumerable: true,
67
- };
68
- },
69
- has: (target, name: string) => target.keys.indexOf(name) >= 0,
70
- },
71
- );
72
- };
73
-
74
- const { absoluteFill, absoluteFillObject, hairlineWidth } = BaseStyleSheet;
75
-
76
- const StyleSheet = {
77
- create(source: StyleSource) {
78
- // Create sheet object.
79
- const sheet: StyleSheetDefinition = {
80
- source,
81
- cache: {},
82
- // Placeholder until build method is called.
83
- active: {},
84
- };
85
-
86
- // If initialized, set active sheet based by active theme.
87
- if (activeKey !== null) {
88
- sheet.cache[activeKey] = createSheet(sheet);
89
- sheet.active = sheet.cache[activeKey];
90
- }
91
-
92
- sheets.push(sheet);
93
-
94
- return sheet.active;
95
- },
96
- build(theme: ThemeVariables, key: string = 'default') {
97
- if (!themes[key]) {
98
- themes[key] = theme;
99
- }
100
-
101
- // If theme is already set, we don't need to do anything.
102
- if (key === activeKey) {
103
- return;
104
- }
105
-
106
- // Set new theme active.
107
- activeKey = key;
108
-
109
- // Update style sheets.
110
- sheets.forEach((_, i) => {
111
- // If there is no result for the active theme, we'll create a themed
112
- // style sheet.
113
- if (!sheets[i].cache[key]) {
114
- sheets[i].cache[key] = createSheet(sheets[i]);
115
- }
116
-
117
- // Assign active object, which is also returned from the create
118
- // function, so style changes will be applied on next rerender in
119
- // the components as well.
120
- Object.assign(sheets[i].active, sheets[i].cache[key]);
121
- });
122
- },
123
- value(key: keyof ThemeVariables) {
124
- if (activeKey === null) {
125
- throw new Error('Use of StyleSheet.value() before initializing.');
126
- }
127
-
128
- const theme = themes[activeKey];
129
-
130
- return theme[key];
131
- },
132
- // Add default styles from StyleSheet
133
- absoluteFill,
134
- absoluteFillObject,
135
- hairlineWidth,
136
- };
137
-
138
- export default StyleSheet;
1
+ import { StyleSheet as BaseStyleSheet } from 'react-native';
2
+ import type { ExtendedStyle, BaseStyle, ThemeVariables } from '../types';
3
+
4
+ type StyleSourceEntry =
5
+ | ((theme: object, key: string) => ExtendedStyle)
6
+ | ExtendedStyle;
7
+
8
+ type NamedExtendedStyles<T extends string> = {
9
+ [K in T]: ExtendedStyle;
10
+ };
11
+ type NamedStyles<T extends string> = {
12
+ [K in T]: BaseStyle;
13
+ };
14
+
15
+ type StyleSheetDefinition<T extends string> = {
16
+ source: {
17
+ [K in T]: StyleSourceEntry;
18
+ };
19
+ cache: Record<string, NamedExtendedStyles<T>>;
20
+ active: NamedExtendedStyles<T>;
21
+ };
22
+
23
+ let activeKey: string | null = null;
24
+
25
+ const themes: Record<string, ThemeVariables> = {};
26
+ const sheets: StyleSheetDefinition<string>[] = [];
27
+
28
+ const createSheet = <T extends string>(
29
+ sheet: StyleSheetDefinition<T>,
30
+ ): NamedExtendedStyles<T> => {
31
+ if (!activeKey) {
32
+ throw new Error('No active theme key.');
33
+ }
34
+
35
+ const theme = themes[activeKey];
36
+
37
+ const statelessSource: Partial<NamedStyles<T>> = {};
38
+ const statefulSource: Partial<NamedExtendedStyles<T>> = {};
39
+
40
+ // Apply theme to themeable styles.
41
+ Object.entries(sheet.source).forEach(([key, style]) => {
42
+ // Resolve theme.
43
+ const value = typeof style === 'function' ? style(theme, activeKey) : style;
44
+
45
+ if (typeof value === 'function') {
46
+ statefulSource[key as T] = value;
47
+ } else {
48
+ statelessSource[key as T] = value as BaseStyle;
49
+ }
50
+ });
51
+
52
+ // Wrap stateful and stateless in a proxy, so that we can update the styles on theme change.
53
+ // For using Object.assign below we need some additional methods on the proxy that are mentioned here:
54
+ // https://stackoverflow.com/questions/43185453/object-assign-and-proxies
55
+ return new Proxy(
56
+ {
57
+ keys: Object.keys(sheet.source),
58
+ stateless: BaseStyleSheet.create(statelessSource as NamedStyles<string>),
59
+ stateful: statefulSource,
60
+ },
61
+ {
62
+ get(target, prop: T) {
63
+ return target.stateless[prop] || target.stateful[prop] || undefined;
64
+ },
65
+ ownKeys: (target) => target.keys,
66
+ getOwnPropertyDescriptor(target, name: string) {
67
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
68
+ const proxy = this;
69
+
70
+ return {
71
+ get value() {
72
+ return proxy.get(target, name);
73
+ },
74
+ configurable: true,
75
+ enumerable: true,
76
+ };
77
+ },
78
+ has: (target, name: string) => target.keys.indexOf(name) >= 0,
79
+ },
80
+ ) as NamedExtendedStyles<T>;
81
+ };
82
+
83
+ const { absoluteFill, absoluteFillObject, hairlineWidth } = BaseStyleSheet;
84
+
85
+ const StyleSheet = {
86
+ create<T extends string>(source: { [K in T]: StyleSourceEntry }): {
87
+ [K in T]: ExtendedStyle;
88
+ } {
89
+ // Create sheet object.
90
+ const sheet: StyleSheetDefinition<T> = {
91
+ source,
92
+ cache: {},
93
+ // @ts-expect-error Placeholder until build method is called.
94
+ active: {},
95
+ };
96
+
97
+ // If initialized, set active sheet based by active theme.
98
+ if (activeKey !== null) {
99
+ sheet.cache[activeKey] = createSheet(sheet);
100
+ sheet.active = sheet.cache[activeKey];
101
+ }
102
+
103
+ sheets.push(sheet);
104
+
105
+ return sheet.active;
106
+ },
107
+ build(theme: ThemeVariables, key: string = 'default') {
108
+ if (!themes[key]) {
109
+ themes[key] = theme;
110
+ }
111
+
112
+ // If theme is already set, we don't need to do anything.
113
+ if (key === activeKey) {
114
+ return;
115
+ }
116
+
117
+ // Set new theme active.
118
+ activeKey = key;
119
+
120
+ // Update style sheets.
121
+ sheets.forEach((_, i) => {
122
+ // If there is no result for the active theme, we'll create a themed
123
+ // style sheet.
124
+ if (!sheets[i].cache[key]) {
125
+ sheets[i].cache[key] = createSheet(sheets[i]);
126
+ }
127
+
128
+ // Assign active object, which is also returned from the create
129
+ // function, so style changes will be applied on next rerender in
130
+ // the components as well.
131
+ Object.assign(sheets[i].active, sheets[i].cache[key]);
132
+ });
133
+ },
134
+ value(key: keyof ThemeVariables) {
135
+ if (activeKey === null) {
136
+ throw new Error('Use of StyleSheet.value() before initializing.');
137
+ }
138
+
139
+ const theme = themes[activeKey];
140
+
141
+ return theme[key];
142
+ },
143
+ // Add default styles from StyleSheet
144
+ absoluteFill,
145
+ absoluteFillObject,
146
+ hairlineWidth,
147
+ };
148
+
149
+ export default StyleSheet;
@@ -1,76 +1,79 @@
1
- import css from './css';
2
- import { GRID_BREAKPOINTS } from '../theme/proxies';
3
- import utilities from '../theme/utilities';
4
- import { each } from '../utils';
5
- import type { StyleUtility } from '../types';
6
-
7
- export function makeUtility(options: StyleUtility) {
8
- return each(options.values, (key, value) => {
9
- const name = options.class || options.property;
10
- const suffix = key === 'null' ? '' : `-${key}`;
11
-
12
- // We use css as a function, because of ts-styled-plugin error.
13
- //
14
- // Equivalent code:
15
- // css`
16
- // ${options.property}: ${value};
17
- // `
18
-
19
- const styles = {
20
- [`${name}${suffix}`]: css(['', ': ', ';'], options.property, value),
21
- };
22
-
23
- if (!options.responsive) {
24
- return styles;
25
- }
26
-
27
- return {
28
- ...styles,
29
- ...each(GRID_BREAKPOINTS, (breakpoint) => {
30
- if (breakpoint === 'xs') {
31
- return {};
32
- }
33
-
34
- // We use css as a function, because of ts-styled-plugin error.
35
- //
36
- // Equivalent code:
37
- // css`
38
- // @include media-breakpoint-up(${breakpoint}) {
39
- // ${options.property}: ${value};
40
- // }
41
- // `
42
-
43
- return {
44
- [`${name}-${breakpoint}${suffix}`]: css(
45
- ['@include media-breakpoint-up(', ') {\n', ': ', ';\n}'],
46
- breakpoint,
47
- options.property,
48
- value,
49
- ),
50
- };
51
- }),
52
- };
53
- });
54
- }
55
-
56
- export default function makeUtilities(
57
- resolve:
58
- | Record<string, StyleUtility>
59
- | ((u: Record<string, StyleUtility>) => Record<string, StyleUtility>),
60
- ) {
61
- const customUtilities =
62
- typeof resolve === 'function' ? resolve(utilities) : resolve;
63
-
64
- const definitions = Object.values({
65
- ...utilities,
66
- ...customUtilities,
67
- }).reduce((result, utility) => {
68
- if (!utility) {
69
- return result;
70
- }
71
-
72
- return Object.assign(result, makeUtility(utility));
73
- }, {});
74
-
75
- return definitions;
76
- }
1
+ import css from './css';
2
+ import { GRID_BREAKPOINTS } from '../theme/proxies';
3
+ import utilities from '../theme/utilities';
4
+ import { each } from '../utils';
5
+ import type { ExtendedStyle, StyleUtility } from '../types';
6
+
7
+ export function makeUtility(options: StyleUtility) {
8
+ return each(options.values, (key, value) => {
9
+ const name = options.class || options.property;
10
+ const suffix = key === 'null' ? '' : `-${key}`;
11
+
12
+ // We use css as a function, because of ts-styled-plugin error.
13
+ //
14
+ // Equivalent code:
15
+ // css`
16
+ // ${options.property}: ${value};
17
+ // `
18
+
19
+ const styles = {
20
+ [`${name}${suffix}`]: css(['', ': ', ';'], options.property, value),
21
+ };
22
+
23
+ if (!options.responsive) {
24
+ return styles;
25
+ }
26
+
27
+ return {
28
+ ...styles,
29
+ ...each(GRID_BREAKPOINTS, (breakpoint) => {
30
+ if (breakpoint === 'xs') {
31
+ return {};
32
+ }
33
+
34
+ // We use css as a function, because of ts-styled-plugin error.
35
+ //
36
+ // Equivalent code:
37
+ // css`
38
+ // @include media-breakpoint-up(${breakpoint}) {
39
+ // ${options.property}: ${value};
40
+ // }
41
+ // `
42
+
43
+ return {
44
+ [`${name}-${breakpoint}${suffix}`]: css(
45
+ ['@include media-breakpoint-up(', ') {\n', ': ', ';\n}'],
46
+ breakpoint,
47
+ options.property,
48
+ value,
49
+ ),
50
+ };
51
+ }),
52
+ };
53
+ });
54
+ }
55
+
56
+ export default function makeUtilities<T extends string>(
57
+ resolve:
58
+ | { [K in T]: StyleUtility }
59
+ | ((u: Record<string, StyleUtility>) => { [K in T]: StyleUtility }),
60
+ ) {
61
+ const customUtilities =
62
+ typeof resolve === 'function' ? resolve(utilities) : resolve;
63
+
64
+ const definitions = Object.values({
65
+ ...utilities,
66
+ ...customUtilities,
67
+ }).reduce(
68
+ (result, utility) => {
69
+ if (!utility) {
70
+ return result;
71
+ }
72
+
73
+ return Object.assign(result, makeUtility(utility));
74
+ },
75
+ {} as { [K in T]: ExtendedStyle },
76
+ );
77
+
78
+ return definitions;
79
+ }