react-native-ui-lib 8.3.4-snapshot.7802 → 8.3.4-snapshot.7804

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ui-lib",
3
- "version": "8.3.4-snapshot.7802",
3
+ "version": "8.3.4-snapshot.7804",
4
4
  "main": "src/index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "author": "Ethan Sharabi <ethan.shar@gmail.com>",
@@ -9,10 +9,6 @@ import { ButtonDriver } from "../button/Button.driver.new";
9
9
  import { ViewDriver } from "../view/View.driver.new";
10
10
  export const TextFieldDriver = (props, options) => {
11
11
  const driver = usePressableDriver(useComponentDriver(props, options));
12
- const inputDriver = useComponentDriver({
13
- renderTree: props.renderTree,
14
- testID: `${props.testID}.input`
15
- }, options);
16
12
  const floatingPlaceholderDriver = TextDriver({
17
13
  renderTree: props.renderTree,
18
14
  testID: `${props.testID}.floatingPlaceholder`
@@ -45,31 +41,30 @@ export const TextFieldDriver = (props, options) => {
45
41
  renderTree: props.renderTree,
46
42
  testID: `${props.testID}.clearButton.container`
47
43
  });
48
- const getInputElement = () => inputDriver.queryElement() ?? driver.getElement();
49
44
  const getValue = () => {
50
- return getInputElement().props.value ?? getInputElement().props.defaultValue;
45
+ return driver.getElement().props.value ?? driver.getElement().props.defaultValue;
51
46
  };
52
47
  const changeText = text => {
53
- fireEvent.changeText(getInputElement(), text);
48
+ fireEvent.changeText(driver.getElement(), text);
54
49
  };
55
50
  const focus = () => {
56
- fireEvent(getInputElement(), 'focus');
51
+ fireEvent(driver.getElement(), 'focus');
57
52
  };
58
53
  const blur = () => {
59
- fireEvent(getInputElement(), 'blur');
54
+ fireEvent(driver.getElement(), 'blur');
60
55
  };
61
56
  const isEnabled = () => {
62
- return !getInputElement().props.accessibilityState?.disabled;
57
+ return !driver.getElement().props.accessibilityState?.disabled;
63
58
  };
64
59
  const getPlaceholder = () => {
65
60
  const exists = () => {
66
- const hasPlaceholder = !!getInputElement().props.placeholder;
61
+ const hasPlaceholder = !!driver.getElement().props.placeholder;
67
62
  const hasText = !!getValue();
68
63
  return hasPlaceholder && (!hasText || hasText && floatingPlaceholderDriver.exists());
69
64
  };
70
65
  const getText = () => {
71
66
  if (exists()) {
72
- return getInputElement().props.placeholder;
67
+ return driver.getElement().props.placeholder;
73
68
  }
74
69
  };
75
70
  return {
@@ -78,8 +78,6 @@ const TextField = props => {
78
78
  readonly = false,
79
79
  showMandatoryIndication,
80
80
  clearButtonStyle,
81
- testID,
82
- accessibilityLabel: accessibilityLabelProp,
83
81
  ...others
84
82
  } = usePreset(props);
85
83
  const {
@@ -137,31 +135,11 @@ const TextField = props => {
137
135
  const hasValue = fieldState.value !== undefined; // NOTE: not pressable if centered without a value (so can't center placeholder)
138
136
  const inputStyle = useMemo(() => [typographyStyle, colorStyle, others.style, hasValue && centeredTextStyle], [typographyStyle, colorStyle, others.style, centeredTextStyle, hasValue]);
139
137
  const dummyPlaceholderStyle = useMemo(() => [inputStyle, styles.dummyPlaceholder], [inputStyle]);
140
- const defaultAccessibilityLabel = useMemo(() => {
141
- const parts = [];
142
- if (label) {
143
- parts.push(label);
144
- }
145
- if (context.isMandatory) {
146
- parts.push('required');
147
- }
148
- parts.push('textField');
149
- if (helperText) {
150
- parts.push(helperText);
151
- } else if (placeholder) {
152
- parts.push(placeholder);
153
- }
154
- if (showCharCounter && others.maxLength) {
155
- parts.push(`you can enter up to ${others.maxLength} characters`);
156
- }
157
- return parts.join(', ');
158
- }, [label, context.isMandatory, helperText, placeholder, showCharCounter, others.maxLength]);
159
- const accessibilityLabel = accessibilityLabelProp ?? defaultAccessibilityLabel;
160
138
  return <FieldContext.Provider value={context}>
161
- <View {...containerProps} testID={testID} accessible accessibilityLabel={accessibilityLabel} style={[margins, positionStyle, containerStyle, centeredContainerStyle]}>
139
+ <View {...containerProps} style={[margins, positionStyle, containerStyle, centeredContainerStyle]}>
162
140
  <View row spread style={centeredContainerStyle}>
163
- <Label label={label} labelColor={labelColor} labelStyle={_labelStyle} labelProps={labelProps} floatingPlaceholder={floatingPlaceholder} validationMessagePosition={validationMessagePosition} testID={`${testID}.label`} showMandatoryIndication={showMandatoryIndication} enableErrors={enableErrors} />
164
- {validationMessagePosition === ValidationMessagePosition.TOP && <ValidationMessage enableErrors={enableErrors} validate={others.validate} validationMessage={others.validationMessage} validationMessageStyle={_validationMessageStyle} retainValidationSpace={retainValidationSpace && retainTopMessageSpace} testID={`${testID}.validationMessage`} />}
141
+ <Label label={label} labelColor={labelColor} labelStyle={_labelStyle} labelProps={labelProps} floatingPlaceholder={floatingPlaceholder} validationMessagePosition={validationMessagePosition} testID={`${props.testID}.label`} showMandatoryIndication={showMandatoryIndication} enableErrors={enableErrors} />
142
+ {validationMessagePosition === ValidationMessagePosition.TOP && <ValidationMessage enableErrors={enableErrors} validate={others.validate} validationMessage={others.validationMessage} validationMessageStyle={_validationMessageStyle} retainValidationSpace={retainValidationSpace && retainTopMessageSpace} testID={`${props.testID}.validationMessage`} />}
165
143
  {topTrailingAccessory && <View>{topTrailingAccessory}</View>}
166
144
  </View>
167
145
  <View style={[paddings, fieldStyle]} row centerV centerH={centered}>
@@ -180,26 +158,26 @@ const TextField = props => {
180
158
  {Constants.isAndroid && centered && <Text marginR-s1 style={dummyPlaceholderStyle}>
181
159
  {placeholder}
182
160
  </Text>}
183
- {floatingPlaceholder && <FloatingPlaceholder defaultValue={others.defaultValue} placeholder={placeholder} floatingPlaceholderStyle={_floatingPlaceholderStyle} floatingPlaceholderColor={floatingPlaceholderColor} floatOnFocus={floatOnFocus} validationMessagePosition={validationMessagePosition} extraOffset={leadingAccessoryMeasurements?.width} testID={`${testID}.floatingPlaceholder`} showMandatoryIndication={showMandatoryIndication} />}
161
+ {floatingPlaceholder && <FloatingPlaceholder defaultValue={others.defaultValue} placeholder={placeholder} floatingPlaceholderStyle={_floatingPlaceholderStyle} floatingPlaceholderColor={floatingPlaceholderColor} floatOnFocus={floatOnFocus} validationMessagePosition={validationMessagePosition} extraOffset={leadingAccessoryMeasurements?.width} testID={`${props.testID}.floatingPlaceholder`} showMandatoryIndication={showMandatoryIndication} />}
184
162
  <Input hitSlop={{
185
163
  top: 20,
186
164
  bottom: 20
187
- }} placeholderTextColor={hidePlaceholder ? 'transparent' : placeholderTextColor} value={fieldState.value} {...others} testID={`${testID}.input`} readonly={readonly} style={inputStyle} onFocus={onFocus} onBlur={onBlur} onChangeText={onChangeText} placeholder={placeholder} hint={hint} showMandatoryIndication={showMandatoryIndication && !label} />
165
+ }} placeholderTextColor={hidePlaceholder ? 'transparent' : placeholderTextColor} value={fieldState.value} {...others} readonly={readonly} style={inputStyle} onFocus={onFocus} onBlur={onBlur} onChangeText={onChangeText} placeholder={placeholder} hint={hint} showMandatoryIndication={showMandatoryIndication && !label} />
188
166
  </View>}
189
- {showClearButton && <ClearButton onClear={onClear} testID={`${testID}.clearButton`} onChangeText={onChangeText} clearButtonStyle={clearButtonStyle} />}
167
+ {showClearButton && <ClearButton onClear={onClear} testID={`${props.testID}.clearButton`} onChangeText={onChangeText} clearButtonStyle={clearButtonStyle} />}
190
168
  {trailingAccessory}
191
169
  {/* </View> */}
192
170
  </View>
193
171
  <View row spread center={centered}>
194
172
  <View flex={!centered} flexG={centered} marginR-s4={showCharCounter}>
195
- {validationMessagePosition === ValidationMessagePosition.BOTTOM && <ValidationMessage enableErrors={enableErrors} validate={others.validate} validationMessage={others.validationMessage} validationIcon={validationIcon} validationMessageStyle={_validationMessageStyle} retainValidationSpace={retainValidationSpace} testID={`${testID}.validationMessage`} />}
196
- {helperText && <Text $textNeutralHeavy subtext marginT-s1 testID={`${testID}.helperText`}>
173
+ {validationMessagePosition === ValidationMessagePosition.BOTTOM && <ValidationMessage enableErrors={enableErrors} validate={others.validate} validationMessage={others.validationMessage} validationIcon={validationIcon} validationMessageStyle={_validationMessageStyle} retainValidationSpace={retainValidationSpace} testID={`${props.testID}.validationMessage`} />}
174
+ {helperText && <Text $textNeutralHeavy subtext marginT-s1 testID={`${props.testID}.helperText`}>
197
175
  {helperText}
198
176
  </Text>}
199
177
  {bottomAccessory}
200
178
  </View>
201
179
  <View>
202
- {showCharCounter && <CharCounter maxLength={others.maxLength} charCounterStyle={charCounterStyle} testID={`${testID}.charCounter`} />}
180
+ {showCharCounter && <CharCounter maxLength={others.maxLength} charCounterStyle={charCounterStyle} testID={`${props.testID}.charCounter`} />}
203
181
  </View>
204
182
  </View>
205
183
  </View>
@@ -19,10 +19,14 @@ export type GetColorByHexOptions = {
19
19
  export type GeneratePaletteOptions = {
20
20
  /** Whether to adjust the lightness of very light colors (generating darker palette) */
21
21
  adjustLightness?: boolean;
22
- /** Whether to adjust the saturation of colors with high lightness and saturation (unifying saturation level throughout palette) */
22
+ /** Whether to apply the saturation curve to unify saturation levels throughout the palette */
23
23
  adjustSaturation?: boolean;
24
- /** Array of saturation adjustments to apply on the color's tints array (from darkest to lightest).
25
- * The 'adjustSaturation' option must be true */
24
+ /** Custom percentage-based saturation curve indexed by distance from the base color.
25
+ * Overrides the default curve when provided. Each value represents the fraction of the base
26
+ * color's saturation to apply at that distance (e.g. [1.0, 0.89, 0.77, ...]) */
27
+ saturationCurve?: number[];
28
+ /** Array of additive saturation adjustments to apply per-index on the palette (from darkest to lightest).
29
+ * When provided, uses legacy per-index saturation logic instead of the default curve */
26
30
  saturationLevels?: number[];
27
31
  /** Whether to add two extra dark colors usually used for dark mode (generating a palette of 10 instead of 8 colors) */
28
32
  addDarkestTints?: boolean;
@@ -91,7 +95,6 @@ export declare class Colors {
91
95
  adjustSaturation: boolean;
92
96
  addDarkestTints: boolean;
93
97
  avoidReverseOnDark: boolean;
94
- saturationLevels: undefined;
95
98
  };
96
99
  generateColorPalette: ((color: string, options?: GeneratePaletteOptions) => string[]) & _.MemoizedFunction;
97
100
  private generateDesignTokens;
@@ -144,7 +147,7 @@ declare const colorObject: Colors & {
144
147
  green70: string;
145
148
  green80: string;
146
149
  yellow1: string;
147
- yellow5: string; /** Whether to adjust the saturation of colors with high lightness and saturation (unifying saturation level throughout palette) */
150
+ yellow5: string;
148
151
  yellow10: string;
149
152
  yellow20: string;
150
153
  yellow30: string;
@@ -169,7 +172,8 @@ declare const colorObject: Colors & {
169
172
  red20: string;
170
173
  red30: string;
171
174
  red40: string;
172
- red50: string;
175
+ red50: string; /** Array of additive saturation adjustments to apply per-index on the palette (from darkest to lightest).
176
+ * When provided, uses legacy per-index saturation logic instead of the default curve */
173
177
  red60: string;
174
178
  red70: string;
175
179
  red80: string;
@@ -179,7 +183,7 @@ declare const colorObject: Colors & {
179
183
  purple20: string;
180
184
  purple30: string;
181
185
  purple40: string;
182
- purple50: string;
186
+ purple50: string; /** Whether to add two extra dark colors usually used for dark mode (generating a palette of 10 instead of 8 colors) */
183
187
  purple60: string;
184
188
  purple70: string;
185
189
  purple80: string;
@@ -212,7 +216,7 @@ declare const colorObject: Colors & {
212
216
  $backgroundGeneralHeavy: string;
213
217
  $backgroundGeneralMedium: string;
214
218
  $backgroundGeneralLight: string;
215
- $backgroundSuccessHeavy: string; /** Whether to adjust the lightness of very light colors (generating darker palette) */
219
+ $backgroundSuccessHeavy: string;
216
220
  $backgroundSuccessLight: string;
217
221
  $backgroundWarningHeavy: string;
218
222
  $backgroundWarningLight: string;
@@ -258,16 +262,10 @@ declare const colorObject: Colors & {
258
262
  $outlineNeutralHeavy: string;
259
263
  $outlinePrimary: string;
260
264
  $outlinePrimaryMedium: string;
261
- $outlineGeneral: string; /**
262
- * Get app's current color scheme
263
- */
265
+ $outlineGeneral: string;
264
266
  $outlineWarning: string;
265
267
  $outlineDanger: string;
266
- $outlineInverted: string; /**
267
- * Set color scheme for app
268
- * arguments:
269
- * scheme - color scheme e.g light/dark/default
270
- */
268
+ $outlineInverted: string;
271
269
  $black: string;
272
270
  $white: string;
273
271
  };
@@ -1,4 +1,3 @@
1
- import _map from "lodash/map";
2
1
  import _clamp from "lodash/clamp";
3
2
  import _toLower from "lodash/toLower";
4
3
  import _toUpper from "lodash/toUpper";
@@ -20,6 +19,9 @@ import DesignTokensDM from "./designTokensDM";
20
19
  import ColorName from "./colorName";
21
20
  import Scheme from "./scheme";
22
21
  import LogService from "../services/LogService";
22
+ const SATURATION_CURVE = [1.0, 0.89, 0.77, 0.65, 0.55, 0.47, 0.42, 0.38, 0.34, 0.30];
23
+ const SATURATION_THRESHOLD = 50;
24
+ const SATURATION_FLOOR = 20;
23
25
  export class Colors {
24
26
  shouldSupportDarkMode = false;
25
27
  constructor() {
@@ -229,15 +231,14 @@ export class Colors {
229
231
  const start = options?.addDarkestTints && colorLightness > 10 ? -size : 0;
230
232
  const end = options?.addDarkestTints && colorLightness > 10 ? undefined : size;
231
233
  const sliced = tints.slice(start, end);
232
- const adjusted = options?.adjustSaturation && adjustSaturation(sliced, color, options?.saturationLevels);
234
+ const adjusted = options?.adjustSaturation && adjustSaturation(sliced, color, options);
233
235
  return adjusted || sliced;
234
236
  }, generatePaletteCacheResolver);
235
237
  defaultPaletteOptions = {
236
238
  adjustLightness: true,
237
239
  adjustSaturation: true,
238
240
  addDarkestTints: false,
239
- avoidReverseOnDark: false,
240
- saturationLevels: undefined
241
+ avoidReverseOnDark: false
241
242
  };
242
243
  generateColorPalette = _memoize((color, options) => {
243
244
  const _options = {
@@ -308,46 +309,46 @@ export class Colors {
308
309
  function colorStringValue(color) {
309
310
  return color?.toString();
310
311
  }
311
- function adjustAllSaturations(colors, baseColor, levels) {
312
- const array = [];
313
- _forEach(colors, (c, index) => {
314
- if (c === baseColor) {
315
- array[index] = baseColor;
316
- } else {
317
- const hsl = Color(c).hsl();
318
- const saturation = hsl.color[1];
319
- const level = levels[index];
320
- if (level !== undefined) {
321
- const saturationLevel = saturation + level;
322
- const clampedLevel = _clamp(saturationLevel, 0, 100);
323
- const adjusted = setSaturation(c, clampedLevel);
324
- array[index] = adjusted;
325
- }
312
+ function adjustSaturation(colors, baseColor, options) {
313
+ if (options?.saturationLevels) {
314
+ return adjustSaturationByLevels(colors, baseColor, options.saturationLevels);
315
+ }
316
+ return adjustSaturationWithCurve(colors, baseColor, options?.saturationCurve);
317
+ }
318
+ function adjustSaturationByLevels(colors, baseColor, levels) {
319
+ return colors.map((color, index) => {
320
+ if (color === baseColor) {
321
+ return baseColor;
326
322
  }
323
+ const level = levels[index];
324
+ if (level === undefined) {
325
+ return color;
326
+ }
327
+ const hsl = Color(color).hsl();
328
+ const newSaturation = _clamp(hsl.color[1] + level, 0, 100);
329
+ return Color.hsl(hsl.color[0], newSaturation, hsl.color[2]).hex();
327
330
  });
328
- return array;
329
331
  }
330
- function adjustSaturation(colors, baseColor, levels) {
331
- if (levels) {
332
- return adjustAllSaturations(colors, baseColor, levels);
332
+ function adjustSaturationWithCurve(colors, baseColor, customCurve) {
333
+ const baseSaturation = Color(baseColor).hsl().color[1];
334
+ if (baseSaturation <= SATURATION_THRESHOLD) {
335
+ return null;
333
336
  }
334
- let array;
335
- const lightnessLevel = 80;
336
- const saturationLevel = 60;
337
- const hsl = Color(baseColor).hsl();
338
- const lightness = Math.round(hsl.color[2]);
339
- if (lightness > lightnessLevel) {
340
- const saturation = Math.round(hsl.color[1]);
341
- if (saturation > saturationLevel) {
342
- array = _map(colors, e => e !== baseColor ? setSaturation(e, saturationLevel) : e);
343
- }
337
+ const baseIndex = colors.indexOf(baseColor.toUpperCase());
338
+ if (baseIndex === -1) {
339
+ return null;
344
340
  }
345
- return array;
346
- }
347
- function setSaturation(color, saturation) {
348
- const hsl = Color(color).hsl();
349
- hsl.color[1] = saturation;
350
- return hsl.hex();
341
+ const curve = customCurve ?? SATURATION_CURVE;
342
+ return colors.map((hex, i) => {
343
+ if (i === baseIndex) {
344
+ return hex;
345
+ }
346
+ const hsl = Color(hex).hsl();
347
+ const distance = Math.abs(i - baseIndex);
348
+ const percentage = curve[Math.min(distance, curve.length - 1)];
349
+ const newSaturation = Math.max(SATURATION_FLOOR, Math.round(baseSaturation * percentage));
350
+ return Color.hsl(hsl.color[0], newSaturation, hsl.color[2]).hex();
351
+ });
351
352
  }
352
353
  function generateColorTint(color, tintLevel) {
353
354
  const hsl = Color(color).hsl();