UNPKG

4.37 kBJavaScriptView Raw
1import { CssProperty, InheritedCssProperty, Property } from '../ui/core/properties';
2import { booleanConverter } from '../ui/core/view-base';
3import { Style } from '../ui/styling/style';
4import { AccessibilityLiveRegion, AccessibilityRole, AccessibilityState } from './accessibility-types';
5function makePropertyEnumConverter(enumValues) {
6 return (value) => {
7 if (!value || typeof value !== 'string') {
8 return null;
9 }
10 for (const [enumKey, enumValue] of Object.entries(enumValues)) {
11 if (typeof enumKey !== 'string') {
12 continue;
13 }
14 if (enumKey === value || `${enumValue}`.toLowerCase() === `${value}`.toLowerCase()) {
15 return enumValue;
16 }
17 }
18 return null;
19 };
20}
21export const accessibilityEnabledProperty = new CssProperty({
22 name: 'accessible',
23 defaultValue: true,
24 cssName: 'a11y-enabled',
25 valueConverter: booleanConverter,
26});
27accessibilityEnabledProperty.register(Style);
28export const iosAccessibilityAdjustsFontSizeProperty = new InheritedCssProperty({
29 defaultValue: false,
30 name: 'iosAccessibilityAdjustsFontSize',
31 cssName: 'ios-a11y-adjusts-font-size',
32 valueConverter: booleanConverter,
33});
34iosAccessibilityAdjustsFontSizeProperty.register(Style);
35export const iosAccessibilityMinFontScaleProperty = new InheritedCssProperty({
36 defaultValue: 0,
37 name: 'iosAccessibilityMinFontScale',
38 cssName: 'ios-a11y-min-font-scale',
39 valueConverter: parseFloat,
40});
41iosAccessibilityMinFontScaleProperty.register(Style);
42export const iosAccessibilityMaxFontScaleProperty = new InheritedCssProperty({
43 defaultValue: 0,
44 name: 'iosAccessibilityMaxFontScale',
45 cssName: 'ios-a11y-max-font-scale',
46 valueConverter: parseFloat,
47});
48iosAccessibilityMaxFontScaleProperty.register(Style);
49export const accessibilityHiddenProperty = new (__APPLE__ ? InheritedCssProperty : CssProperty)({
50 name: 'accessibilityHidden',
51 cssName: 'a11y-hidden',
52 valueConverter: booleanConverter,
53});
54accessibilityHiddenProperty.register(Style);
55export const accessibilityIdentifierProperty = new Property({
56 name: 'accessibilityIdentifier',
57});
58export const accessibilityRoleProperty = new CssProperty({
59 name: 'accessibilityRole',
60 cssName: 'a11y-role',
61 valueConverter: makePropertyEnumConverter(AccessibilityRole),
62});
63accessibilityRoleProperty.register(Style);
64export const accessibilityStateProperty = new CssProperty({
65 name: 'accessibilityState',
66 cssName: 'a11y-state',
67 valueConverter: makePropertyEnumConverter(AccessibilityState),
68});
69accessibilityStateProperty.register(Style);
70export const accessibilityLabelProperty = new Property({
71 name: 'accessibilityLabel',
72});
73export const accessibilityValueProperty = new Property({
74 name: 'accessibilityValue',
75});
76export const accessibilityHintProperty = new Property({
77 name: 'accessibilityHint',
78});
79export const accessibilityIgnoresInvertColorsProperty = new Property({
80 name: 'accessibilityIgnoresInvertColors',
81 valueConverter: booleanConverter,
82});
83export const accessibilityLiveRegionProperty = new CssProperty({
84 name: 'accessibilityLiveRegion',
85 cssName: 'a11y-live-region',
86 defaultValue: AccessibilityLiveRegion.None,
87 valueConverter: makePropertyEnumConverter(AccessibilityLiveRegion),
88});
89accessibilityLiveRegionProperty.register(Style);
90export const accessibilityTraitsProperty = new Property({
91 name: 'accessibilityTraits',
92});
93export const accessibilityLanguageProperty = new CssProperty({
94 name: 'accessibilityLanguage',
95 cssName: 'a11y-lang',
96});
97accessibilityLanguageProperty.register(Style);
98export const accessibilityMediaSessionProperty = new CssProperty({
99 name: 'accessibilityMediaSession',
100 cssName: 'a11y-media-session',
101});
102accessibilityMediaSessionProperty.register(Style);
103/**
104 * Represents the observable property backing the accessibilityStep property.
105 */
106export const accessibilityStepProperty = new CssProperty({
107 name: 'accessibilityStep',
108 cssName: 'a11y-step',
109 defaultValue: 10,
110 valueConverter: (v) => {
111 const step = parseFloat(v);
112 if (isNaN(step) || step <= 0) {
113 return 10;
114 }
115 return step;
116 },
117});
118accessibilityStepProperty.register(Style);
119//# sourceMappingURL=accessibility-properties.js.map
\No newline at end of file