Skip to content

Commit 295e12e

Browse files
authored
No static locale infra (#2684)
1 parent 42d6b1a commit 295e12e

File tree

3 files changed

+56
-16
lines changed

3 files changed

+56
-16
lines changed

src/components/colorPicker/colorPicker.api.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
"description": "Callback for the picker's color palette change"
2727
},
2828
{
29-
"name": "accessibilityLabels",
30-
"type": "{\n addButton: string,\n dismissButton: string,\n doneButton: string,\n input: string}",
31-
"description": "Accessibility labels as an object of strings",
32-
"default": "{\n addButton: 'add custom color using hex code',\n dismissButton: 'dismiss',\n doneButton: 'done',\n input: 'custom hex color code'\n}"
29+
"name": "getAccessibilityLabels",
30+
"type": "() => {\n addButton: string,\n dismissButton: string,\n doneButton: string,\n input: string}",
31+
"description": "A function that returns the accessibility labels as an object of strings",
32+
"default": "() => {\n addButton: 'add custom color using hex code',\n dismissButton: 'dismiss',\n doneButton: 'done',\n input: 'custom hex color code'\n}"
3333
},
3434
{"name": "testID", "type": "string", "description": "The test id for e2e tests"},
3535
{"name": "backgroundColor", "type": "string", "description": "The ColorPicker's background color"}

src/components/colorPicker/index.tsx

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import ColorPalette, {ColorPaletteProps} from '../colorPalette';
88
import {SWATCH_MARGIN, SWATCH_SIZE} from '../colorSwatch';
99
import ColorPickerDialog, {ColorPickerDialogProps} from './ColorPickerDialog';
1010

11+
interface AccessibilityLabels {
12+
addButton?: string;
13+
dismissButton?: string;
14+
doneButton?: string;
15+
input?: string;
16+
}
17+
1118
interface Props extends ColorPickerDialogProps, Pick<ColorPaletteProps, 'onValueChange'> {
1219
/**
1320
* Array of colors for the picker's color palette (hex values)
@@ -29,13 +36,19 @@ interface Props extends ColorPickerDialogProps, Pick<ColorPaletteProps, 'onValue
2936
* doneButton: 'done',
3037
* input: 'custom hex color code'
3138
* }
39+
* @deprecated
3240
*/
33-
accessibilityLabels?: {
34-
addButton?: string;
35-
dismissButton?: string;
36-
doneButton?: string;
37-
input?: string;
38-
};
41+
accessibilityLabels?: AccessibilityLabels;
42+
/**
43+
* A function that returns the accessibility labels as an object of strings, ex.
44+
* {
45+
* addButton: 'add custom color using hex code',
46+
* dismissButton: 'dismiss',
47+
* doneButton: 'done',
48+
* input: 'custom hex color code'
49+
* }
50+
*/
51+
getAccessibilityLabels?: () => AccessibilityLabels;
3952
testID?: string;
4053
/**
4154
* The ColorPicker's background color
@@ -61,7 +74,7 @@ class ColorPicker extends PureComponent<Props> {
6174
static displayName = 'ColorPicker';
6275

6376
static defaultProps = {
64-
accessibilityLabels: ACCESSIBILITY_LABELS,
77+
getAccessibilityLabels: () => ACCESSIBILITY_LABELS,
6578
backgroundColor: Colors.$backgroundDefault
6679
};
6780

@@ -86,7 +99,17 @@ class ColorPicker extends PureComponent<Props> {
8699
};
87100

88101
render() {
89-
const {initialColor, colors, value, testID, accessibilityLabels, backgroundColor, onValueChange} = this.props;
102+
const {
103+
initialColor,
104+
colors,
105+
value,
106+
testID,
107+
accessibilityLabels: deprecatedAccessibilityLabels,
108+
getAccessibilityLabels,
109+
backgroundColor,
110+
onValueChange
111+
} = this.props;
112+
const accessibilityLabels = deprecatedAccessibilityLabels ?? getAccessibilityLabels?.();
90113
const {show} = this.state;
91114
return (
92115
<View row testID={testID} style={{backgroundColor}}>

src/components/slider/ColorSliderGroup.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import Text from '../text';
88

99
type SliderOnValueChange = (value: string) => void;
1010

11+
type Labels = {[key in GradientSliderTypes]: string};
12+
1113
export type ColorSliderGroupProps = {
1214
/**
1315
* The gradient color
@@ -29,11 +31,17 @@ export type ColorSliderGroupProps = {
2931
* Show the sliders labels (defaults are: Hue, Lightness, Saturation)
3032
*/
3133
showLabels?: boolean;
34+
/**
35+
* In case you would like to change the default labels (translations etc.), you can provide
36+
* this prop with a map to the relevant labels ({hue: ..., lightness: ..., saturation: ...}).
37+
* @deprecated
38+
*/
39+
labels?: Labels;
3240
/**
3341
* In case you would like to change the default labels (translations etc.), you can provide
3442
* this prop with a map to the relevant labels ({hue: ..., lightness: ..., saturation: ...}).
3543
*/
36-
labels?: {[key in GradientSliderTypes]: string};
44+
getLabels?: () => Labels;
3745
/**
3846
* The labels style
3947
*/
@@ -42,7 +50,7 @@ export type ColorSliderGroupProps = {
4250
* If true the component will have accessibility features enabled
4351
*/
4452
accessible?: boolean;
45-
/**
53+
/**
4654
* Whether to use the new Slider implementation using Reanimated
4755
*/
4856
migrate?: boolean;
@@ -61,7 +69,7 @@ class ColorSliderGroup extends PureComponent<ColorSliderGroupProps, ColorSliderG
6169
static displayName = 'ColorSliderGroup';
6270

6371
static defaultProps = {
64-
labels: {hue: 'Hue', lightness: 'Lightness', saturation: 'Saturation'}
72+
getLabels: () => ({hue: 'Hue', lightness: 'Lightness', saturation: 'Saturation'})
6573
};
6674

6775
state = {
@@ -83,7 +91,16 @@ class ColorSliderGroup extends PureComponent<ColorSliderGroupProps, ColorSliderG
8391
};
8492

8593
renderSlider = (type: GradientSliderTypes) => {
86-
const {sliderContainerStyle, showLabels, labelsStyle, accessible, labels, migrate} = this.props;
94+
const {
95+
sliderContainerStyle,
96+
showLabels,
97+
labelsStyle,
98+
accessible,
99+
labels: deprecatedLabels,
100+
getLabels,
101+
migrate
102+
} = this.props;
103+
const labels = deprecatedLabels ?? getLabels?.();
87104

88105
return (
89106
<>

0 commit comments

Comments
 (0)