@unif/react-native-design 0.27.1 → 0.29.0

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 (75) hide show
  1. package/README.md +3 -3
  2. package/lib/module/components/ui/CircularProgress/CircularProgress.js +108 -0
  3. package/lib/module/components/ui/CircularProgress/CircularProgress.js.map +1 -0
  4. package/lib/module/components/ui/CircularProgress/index.js +4 -0
  5. package/lib/module/components/ui/CircularProgress/index.js.map +1 -0
  6. package/lib/module/components/ui/CircularProgress/normalizeCircularProgress.js +42 -0
  7. package/lib/module/components/ui/CircularProgress/normalizeCircularProgress.js.map +1 -0
  8. package/lib/module/components/ui/CircularProgress/types.js +4 -0
  9. package/lib/module/components/ui/CircularProgress/types.js.map +1 -0
  10. package/lib/module/components/ui/Ribbon/Ribbon.js +70 -0
  11. package/lib/module/components/ui/Ribbon/Ribbon.js.map +1 -0
  12. package/lib/module/components/ui/Ribbon/index.js +4 -0
  13. package/lib/module/components/ui/Ribbon/index.js.map +1 -0
  14. package/lib/module/components/ui/Ribbon/layout.js +26 -0
  15. package/lib/module/components/ui/Ribbon/layout.js.map +1 -0
  16. package/lib/module/components/ui/Ribbon/styles.js +44 -0
  17. package/lib/module/components/ui/Ribbon/styles.js.map +1 -0
  18. package/lib/module/components/ui/Ribbon/types.js +4 -0
  19. package/lib/module/components/ui/Ribbon/types.js.map +1 -0
  20. package/lib/module/components/ui/Stepper/Stepper.js +12 -2
  21. package/lib/module/components/ui/Stepper/Stepper.js.map +1 -1
  22. package/lib/module/components/ui/Stepper/displayValue.js +6 -0
  23. package/lib/module/components/ui/Stepper/displayValue.js.map +1 -0
  24. package/lib/module/components/ui/Stepper/layout.js +19 -1
  25. package/lib/module/components/ui/Stepper/layout.js.map +1 -1
  26. package/lib/module/components/ui/Stepper/styles.js +9 -1
  27. package/lib/module/components/ui/Stepper/styles.js.map +1 -1
  28. package/lib/module/components/ui/index.js +2 -0
  29. package/lib/module/components/ui/index.js.map +1 -1
  30. package/lib/typescript/src/components/ui/CircularProgress/CircularProgress.d.ts +3 -0
  31. package/lib/typescript/src/components/ui/CircularProgress/CircularProgress.d.ts.map +1 -0
  32. package/lib/typescript/src/components/ui/CircularProgress/index.d.ts +3 -0
  33. package/lib/typescript/src/components/ui/CircularProgress/index.d.ts.map +1 -0
  34. package/lib/typescript/src/components/ui/CircularProgress/normalizeCircularProgress.d.ts +15 -0
  35. package/lib/typescript/src/components/ui/CircularProgress/normalizeCircularProgress.d.ts.map +1 -0
  36. package/lib/typescript/src/components/ui/CircularProgress/types.d.ts +24 -0
  37. package/lib/typescript/src/components/ui/CircularProgress/types.d.ts.map +1 -0
  38. package/lib/typescript/src/components/ui/Ribbon/Ribbon.d.ts +4 -0
  39. package/lib/typescript/src/components/ui/Ribbon/Ribbon.d.ts.map +1 -0
  40. package/lib/typescript/src/components/ui/Ribbon/index.d.ts +3 -0
  41. package/lib/typescript/src/components/ui/Ribbon/index.d.ts.map +1 -0
  42. package/lib/typescript/src/components/ui/Ribbon/layout.d.ts +23 -0
  43. package/lib/typescript/src/components/ui/Ribbon/layout.d.ts.map +1 -0
  44. package/lib/typescript/src/components/ui/Ribbon/styles.d.ts +31 -0
  45. package/lib/typescript/src/components/ui/Ribbon/styles.d.ts.map +1 -0
  46. package/lib/typescript/src/components/ui/Ribbon/types.d.ts +18 -0
  47. package/lib/typescript/src/components/ui/Ribbon/types.d.ts.map +1 -0
  48. package/lib/typescript/src/components/ui/Stepper/Stepper.d.ts +1 -1
  49. package/lib/typescript/src/components/ui/Stepper/Stepper.d.ts.map +1 -1
  50. package/lib/typescript/src/components/ui/Stepper/displayValue.d.ts +2 -0
  51. package/lib/typescript/src/components/ui/Stepper/displayValue.d.ts.map +1 -0
  52. package/lib/typescript/src/components/ui/Stepper/layout.d.ts +2 -0
  53. package/lib/typescript/src/components/ui/Stepper/layout.d.ts.map +1 -1
  54. package/lib/typescript/src/components/ui/Stepper/styles.d.ts +2 -1
  55. package/lib/typescript/src/components/ui/Stepper/styles.d.ts.map +1 -1
  56. package/lib/typescript/src/components/ui/Stepper/types.d.ts +4 -2
  57. package/lib/typescript/src/components/ui/Stepper/types.d.ts.map +1 -1
  58. package/lib/typescript/src/components/ui/index.d.ts +4 -0
  59. package/lib/typescript/src/components/ui/index.d.ts.map +1 -1
  60. package/package.json +1 -1
  61. package/src/components/ui/CircularProgress/CircularProgress.tsx +111 -0
  62. package/src/components/ui/CircularProgress/index.ts +2 -0
  63. package/src/components/ui/CircularProgress/normalizeCircularProgress.ts +64 -0
  64. package/src/components/ui/CircularProgress/types.ts +24 -0
  65. package/src/components/ui/Ribbon/Ribbon.tsx +92 -0
  66. package/src/components/ui/Ribbon/index.ts +2 -0
  67. package/src/components/ui/Ribbon/layout.ts +33 -0
  68. package/src/components/ui/Ribbon/styles.ts +33 -0
  69. package/src/components/ui/Ribbon/types.ts +19 -0
  70. package/src/components/ui/Stepper/Stepper.tsx +15 -3
  71. package/src/components/ui/Stepper/displayValue.ts +6 -0
  72. package/src/components/ui/Stepper/layout.ts +28 -9
  73. package/src/components/ui/Stepper/styles.ts +4 -1
  74. package/src/components/ui/Stepper/types.ts +4 -2
  75. package/src/components/ui/index.ts +4 -0
@@ -0,0 +1,33 @@
1
+ import { StyleSheet } from 'react-native';
2
+ import { fw, radius, space, type as t, type ColorTokens } from '../../../theme';
3
+ import type { RibbonTone } from './types';
4
+
5
+ export const makeStyles = (_c: ColorTokens) =>
6
+ StyleSheet.create({
7
+ root: { position: 'relative' },
8
+ visual: { alignItems: 'flex-end' },
9
+ bar: {
10
+ flexDirection: 'row',
11
+ alignItems: 'center',
12
+ paddingHorizontal: space['3'],
13
+ borderTopLeftRadius: radius.xs,
14
+ borderBottomLeftRadius: radius.xs,
15
+ },
16
+ text: { fontSize: t.micro, fontWeight: fw.medium },
17
+ fold: {
18
+ borderRightColor: 'transparent',
19
+ borderBottomColor: 'transparent',
20
+ },
21
+ });
22
+
23
+ export function paletteFor(
24
+ tone: RibbonTone,
25
+ c: ColorTokens
26
+ ): { bg: string; fg: string; fold: string } {
27
+ switch (tone) {
28
+ case 'brand':
29
+ return { bg: c.primary, fg: c.onPrimary, fold: c.primaryPressed };
30
+ case 'danger':
31
+ return { bg: c.error, fg: c.onError, fold: c.error };
32
+ }
33
+ }
@@ -0,0 +1,19 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { StyleProp, ViewStyle } from 'react-native';
3
+
4
+ export type RibbonTone = 'brand' | 'danger';
5
+
6
+ export type RibbonProps = {
7
+ /** 右上缎带的可见文案 */
8
+ label: string;
9
+ /** 语义色,默认 'brand' */
10
+ tone?: RibbonTone;
11
+ /** 被缎带标记的内容 */
12
+ children: ReactNode;
13
+ /** 可选读屏文案;不传时缎带只作为装饰,避免与内容重复播报 */
14
+ accessibilityLabel?: string;
15
+ /** 外层布局样式 */
16
+ style?: StyleProp<ViewStyle>;
17
+ /** E2E / 测试定位 */
18
+ testID?: string;
19
+ };
@@ -11,6 +11,7 @@ import { childTestID } from '../../../utils/testID';
11
11
  import { A11Y_HIDDEN_PROPS } from '../shared/a11y';
12
12
  import { normalizeNonBlankText } from '../shared/accessibilityName';
13
13
  import { getStepperValueAccessibilityProps } from './accessibility';
14
+ import { resolveStepperDisplayValue } from './displayValue';
14
15
  import { resolveStepperLayout } from './layout';
15
16
  import { nextStepperValue, normalizeStepper } from './normalizeStepper';
16
17
  import { StepperPressable } from './StepperPressable';
@@ -37,6 +38,7 @@ export function Stepper({
37
38
  max,
38
39
  step,
39
40
  size = 'md',
41
+ formatValue,
40
42
  disabled = false,
41
43
  testID,
42
44
  }: StepperProps): React.JSX.Element {
@@ -44,7 +46,7 @@ export function Stepper({
44
46
  const fontScale = useFontScale();
45
47
  const dims = sizingFor(size);
46
48
  const valueFontSize = scaleFontMetric(dims.fs, fontScale);
47
- const layout = resolveStepperLayout(dims);
49
+ const layout = resolveStepperLayout(dims, { compact: size === 'xs' });
48
50
  const accessibleName = normalizeNonBlankText(accessibilityLabel);
49
51
  const hasBlankLabel = accessibleName === undefined;
50
52
  const normalized = normalizeStepper({
@@ -56,6 +58,7 @@ export function Stepper({
56
58
  });
57
59
  const { safeMin, safeStep, safeValue, canDecrement, canIncrement } =
58
60
  normalized;
61
+ const displayValue = resolveStepperDisplayValue(safeValue, formatValue);
59
62
  const decrementValue = nextStepperValue(normalized, 'decrement');
60
63
  const incrementValue = nextStepperValue(normalized, 'increment');
61
64
  const valueAccessibilityProps = getStepperValueAccessibilityProps({
@@ -161,8 +164,17 @@ export function Stepper({
161
164
  style={[styles.cell, { width: dims.w, height: dims.h }]}
162
165
  testID={childTestID(testID, 'value-visual')}
163
166
  >
164
- <Text style={[styles.valueText, { fontSize: valueFontSize }]}>
165
- {safeValue}
167
+ <Text
168
+ {...(formatValue === undefined
169
+ ? {}
170
+ : {
171
+ adjustsFontSizeToFit: true,
172
+ minimumFontScale: 0.75,
173
+ numberOfLines: 1,
174
+ })}
175
+ style={[styles.valueText, { fontSize: valueFontSize }]}
176
+ >
177
+ {displayValue}
166
178
  </Text>
167
179
  </View>
168
180
  </View>
@@ -0,0 +1,6 @@
1
+ export function resolveStepperDisplayValue(
2
+ value: number,
3
+ formatValue?: (value: number) => string
4
+ ): number | string {
5
+ return formatValue === undefined ? value : formatValue(value);
6
+ }
@@ -14,15 +14,34 @@ export type ResolvedStepperLayout = {
14
14
  };
15
15
  };
16
16
 
17
- export function resolveStepperLayout({
18
- h,
19
- btn,
20
- w,
21
- }: {
22
- h: number;
23
- btn: number;
24
- w: number;
25
- }): ResolvedStepperLayout {
17
+ export function resolveStepperLayout(
18
+ {
19
+ h,
20
+ btn,
21
+ w,
22
+ }: {
23
+ h: number;
24
+ btn: number;
25
+ w: number;
26
+ },
27
+ options?: { compact?: boolean }
28
+ ): ResolvedStepperLayout {
29
+ if (options?.compact === true) {
30
+ return {
31
+ decrementFrame: {
32
+ width: btn,
33
+ height: fixed.hitTarget,
34
+ alignItems: 'flex-end',
35
+ },
36
+ valueFrame: { width: w, height: fixed.hitTarget },
37
+ incrementFrame: {
38
+ width: btn,
39
+ height: fixed.hitTarget,
40
+ alignItems: 'flex-start',
41
+ },
42
+ };
43
+ }
44
+
26
45
  const sideWidth = Math.max(fixed.hitTarget, btn);
27
46
  const outerHeight = Math.max(fixed.hitTarget, h);
28
47
  return {
@@ -52,7 +52,8 @@ export const makeStyles = (c: ColorTokens) =>
52
52
  },
53
53
  });
54
54
 
55
- /** Stepper 尺寸推导:sm(control.sm=`r(28)` 高 / `r(28)` 按钮 / r(40) 值宽 / xs 字)/
55
+ /** Stepper 尺寸推导:xs(r(24) 高 / r(24) 按钮 / r(40) 值宽 / micro 字)/
56
+ * sm(control.sm=`r(28)` 高 / `r(28)` 按钮 / r(40) 值宽 / xs 字)/
56
57
  * md(r(32) 高 / r(32) 按钮 / r(48) 值宽 / sm 字)。
57
58
  * 新增 size 在 types.ts 加 union + 这里加 case。 */
58
59
  export function sizingFor(size: StepperSize): {
@@ -62,6 +63,8 @@ export function sizingFor(size: StepperSize): {
62
63
  fs: number;
63
64
  } {
64
65
  switch (size) {
66
+ case 'xs':
67
+ return { h: r(24), btn: r(24), w: r(40), fs: t.micro };
65
68
  case 'sm':
66
69
  return { h: control.sm, btn: control.sm, w: r(40), fs: t.xs };
67
70
  case 'md':
@@ -1,5 +1,5 @@
1
- /** Stepper 尺寸:sm=28px / md=32px */
2
- export type StepperSize = 'sm' | 'md';
1
+ /** Stepper 尺寸:xs=24px / sm=28px / md=32px */
2
+ export type StepperSize = 'xs' | 'sm' | 'md';
3
3
 
4
4
  export type StepperProps = {
5
5
  /** 当前值(受控) */
@@ -16,6 +16,8 @@ export type StepperProps = {
16
16
  step?: number;
17
17
  /** 尺寸,默认 'md' */
18
18
  size?: StepperSize;
19
+ /** 自定义中央值的可见文案;数值运算与 adjustable 语义仍使用归一化后的 number */
20
+ formatValue?: (value: number) => string;
19
21
  /** 整体禁用(三个操作节点都不暴露 action) */
20
22
  disabled?: boolean;
21
23
  /** E2E / 测试定位 */
@@ -20,6 +20,8 @@ export { Checkbox } from './Checkbox';
20
20
  export type { CheckboxProps } from './Checkbox';
21
21
  export { Chip } from './Chip';
22
22
  export type { ChipProps } from './Chip';
23
+ export { CircularProgress } from './CircularProgress';
24
+ export type { CircularProgressProps } from './CircularProgress';
23
25
  export { confirm, ConfirmHost } from './Confirm';
24
26
  export type { ConfirmOptions } from './Confirm';
25
27
  export { DrawerHeader } from './DrawerHeader';
@@ -55,6 +57,8 @@ export { Radio } from './Radio';
55
57
  export type { GroupProps as RadioGroupProps, RadioProps } from './Radio';
56
58
  export { Reveal } from './Reveal';
57
59
  export type { RevealProps } from './Reveal';
60
+ export { Ribbon } from './Ribbon';
61
+ export type { RibbonProps, RibbonTone } from './Ribbon';
58
62
  export { Search } from './Search';
59
63
  export type { SearchProps } from './Search';
60
64
  export { Skeleton } from './Skeleton';