@apify/ui-library 1.152.2 → 1.152.4-featureexposetestids-bd5e63.21

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 (33) hide show
  1. package/dist/components/badge/badge.d.ts +1 -1
  2. package/dist/components/shortcut/shortcut.d.ts +8 -7
  3. package/dist/components/shortcut/shortcut.d.ts.map +1 -1
  4. package/dist/components/shortcut/shortcut.js +9 -11
  5. package/dist/files_hash_at_build.txt +1 -1
  6. package/dist/src/components/badge/badge.d.ts +1 -1
  7. package/dist/src/components/shortcut/shortcut.d.ts +8 -7
  8. package/dist/src/components/shortcut/shortcut.d.ts.map +1 -1
  9. package/dist/src/components/shortcut/shortcut.js +1 -3
  10. package/dist/src/components/shortcut/shortcut.js.map +1 -1
  11. package/dist/src/test_ids.d.ts +2 -0
  12. package/dist/src/test_ids.d.ts.map +1 -0
  13. package/dist/src/test_ids.js +6 -0
  14. package/dist/src/test_ids.js.map +1 -0
  15. package/dist/src/type_utils.d.ts +22 -0
  16. package/dist/src/type_utils.d.ts.map +1 -1
  17. package/dist/src/type_utils.type-test.d.ts +2 -0
  18. package/dist/src/type_utils.type-test.d.ts.map +1 -0
  19. package/dist/src/type_utils.type-test.js +25 -0
  20. package/dist/src/type_utils.type-test.js.map +1 -0
  21. package/dist/test_ids.d.ts +2 -0
  22. package/dist/test_ids.d.ts.map +1 -0
  23. package/dist/test_ids.js +2 -0
  24. package/dist/tsconfig.build.tsbuildinfo +1 -1
  25. package/dist/type_utils.d.ts +22 -0
  26. package/dist/type_utils.d.ts.map +1 -1
  27. package/dist/type_utils.type-test.d.ts +2 -0
  28. package/dist/type_utils.type-test.d.ts.map +1 -0
  29. package/package.json +15 -3
  30. package/src/components/shortcut/shortcut.tsx +14 -14
  31. package/src/test_ids.ts +5 -0
  32. package/src/type_utils.ts +30 -0
  33. package/src/type_utils.type-test.ts +35 -0
@@ -1,6 +1,28 @@
1
+ import { ComponentPropsWithRef, ComponentPropsWithoutRef, ElementType, ReactNode } from 'react';
1
2
  export type WithTransientProps<T> = {
2
3
  [P in keyof T & string as `$${P}`]: T[P];
3
4
  };
4
5
  export type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
5
6
  export type WithOptional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
7
+ /**
8
+ * Polymorphic component typing helpers (Pattern B) for the `as`-prop pattern in the
9
+ * UI Component Typing RFC. Only for components that switch their element via `as`;
10
+ * others extend `React.ComponentPropsWithoutRef<'element'>` directly (Pattern A).
11
+ */
12
+ /** Ref type for element `E`. Conditional `infer`, not `ComponentPropsWithRef<E>['ref']` — indexed access widens to `unknown` for an unbound generic `E`. */
13
+ export type PolymorphicRef<E extends ElementType> = ComponentPropsWithRef<E> extends {
14
+ ref?: infer R;
15
+ } ? R : never;
16
+ /** `OwnProps` plus the shared `as` and `children`. */
17
+ type PolymorphicOwnProps<E extends ElementType, OwnProps extends object = object> = OwnProps & {
18
+ as?: E;
19
+ children?: ReactNode;
20
+ };
21
+ /** Own props + element `E`'s HTML attributes. Own props win via `Omit` (they replace, not merge with, native typing). */
22
+ export type PolymorphicComponentProps<E extends ElementType, OwnProps extends object = object> = PolymorphicOwnProps<E, OwnProps> & Omit<ComponentPropsWithoutRef<E>, keyof PolymorphicOwnProps<E, OwnProps>>;
23
+ /** Adds a `ref` typed for element `E` (React 19: `ref` is a regular prop, no `forwardRef`). */
24
+ export type PolymorphicComponentPropsWithRef<E extends ElementType, OwnProps extends object = object> = PolymorphicComponentProps<E, OwnProps> & {
25
+ ref?: PolymorphicRef<E>;
26
+ };
27
+ export {};
6
28
  //# sourceMappingURL=type_utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"type_utils.d.ts","sourceRoot":"","sources":["../src/type_utils.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,MAAM,IAAI,IAAI,CAAC,E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,KAAK,mBAAmB,CAAC,CAAC,SAAS,WAAW,EAAE,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,QAAQ,GAAG;IAC3F,EAAE,CAAC,EAAE,CAAC,CAAC;IACP,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB,CAAC;AAEF,yHAAyH;AACzH,MAAM,MAAM,yBAAyB,CAAC,CAAC,SAAS,WAAW,EAAE,QAAQ,SAAS,MAAM,GAAG,MAAM,IAAI,mBAAmB,CAChH,CAAC,EACD,QAAQ,CACX,GACG,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,MAAM,mBAAmB,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;AAE9E,+FAA+F;AAC/F,MAAM,MAAM,gCAAgC,CACxC,CAAC,SAAS,WAAW,EACrB,QAAQ,SAAS,MAAM,GAAG,MAAM,IAChC,yBAAyB,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=type_utils.type-test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type_utils.type-test.d.ts","sourceRoot":"","sources":["../src/type_utils.type-test.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,12 +1,24 @@
1
1
  {
2
2
  "name": "@apify/ui-library",
3
- "version": "1.152.2",
3
+ "version": "1.152.4-featureexposetestids-bd5e63.21+3b6bb4035a8",
4
4
  "description": "React UI library used by apify.com",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "sideEffects": false,
8
8
  "main": "dist/index.js",
9
9
  "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./test-ids": {
16
+ "types": "./dist/test_ids.d.ts",
17
+ "default": "./dist/test_ids.js"
18
+ },
19
+ "./style/*": "./style/*",
20
+ "./package.json": "./package.json"
21
+ },
10
22
  "publishConfig": {
11
23
  "registry": "https://registry.npmjs.org",
12
24
  "access": "public"
@@ -63,7 +75,7 @@
63
75
  "styled-components": "^6.1.19"
64
76
  },
65
77
  "devDependencies": {
66
- "@apify-packages/types": "^3.390.2",
78
+ "@apify-packages/types": "^3.391.0",
67
79
  "@storybook/react-vite": "^10.3.5",
68
80
  "@testing-library/react": "^16.3.2",
69
81
  "@types/hast": "^3.0.4",
@@ -83,5 +95,5 @@
83
95
  "src",
84
96
  "style"
85
97
  ],
86
- "gitHead": "0f5476cbf11d984ceb7ff6c6f6b61932a06d1490"
98
+ "gitHead": "3b6bb4035a8667c17b58dcedf67b7069905806f8"
87
99
  }
@@ -1,16 +1,18 @@
1
- import type { ElementType } from 'react';
1
+ import type { ElementType, ReactNode } from 'react';
2
2
  import styled, { css } from 'styled-components';
3
3
 
4
4
  import { theme } from '../../design_system/theme';
5
+ import type { PolymorphicComponentProps } from '../../type_utils';
5
6
  import { Text } from '../text';
6
7
 
7
- interface ShortcutProps {
8
- as?: ElementType;
9
- className?: string;
10
- children: React.ReactNode;
11
- /* If true, always use dark mode colors */
8
+ type ShortcutOwnProps = {
9
+ /** Always use dark-mode colors (e.g. inside tooltips). */
12
10
  dark?: boolean;
13
- }
11
+ children: ReactNode;
12
+ };
13
+
14
+ // Pattern B (polymorphic `as`). No ref forwarded (wraps `Text`) → WithoutRef variant (RFC Q3).
15
+ export type ShortcutProps<E extends ElementType = 'span'> = PolymorphicComponentProps<E, ShortcutOwnProps>;
14
16
 
15
17
  const adaptiveColors = css`
16
18
  background-color: ${theme.color.neutral.backgroundSubtle};
@@ -36,10 +38,8 @@ const StyledShortcut = styled(Text)<{ $dark?: boolean }>`
36
38
  ${({ $dark }) => ($dark ? darkColors : adaptiveColors)}
37
39
  `;
38
40
 
39
- export const Shortcut = ({ as, className, children, dark = false }: ShortcutProps) => {
40
- return (
41
- <StyledShortcut forwardedAs={as} className={className} $dark={dark} type="code" size="small" weight="medium">
42
- {children}
43
- </StyledShortcut>
44
- );
45
- };
41
+ export const Shortcut = <E extends ElementType = 'span'>({ as, children, dark = false, ...rest }: ShortcutProps<E>) => (
42
+ <StyledShortcut forwardedAs={as} $dark={dark} type="code" size="small" weight="medium" {...rest}>
43
+ {children}
44
+ </StyledShortcut>
45
+ );
@@ -0,0 +1,5 @@
1
+ // Aggregates every `*.test_ids.ts` module in this package behind the `./test-ids`
2
+ // subpath export. Consumers (notably Playwright specs) import test IDs from here to
3
+ // avoid pulling the React/CSS-heavy root barrel, which breaks non-bundler loaders.
4
+ // Add future test ID modules to this barrel.
5
+ export { tableTestIds } from './components/table/table.test_ids.js';
package/src/type_utils.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { ComponentPropsWithRef, ComponentPropsWithoutRef, ElementType, ReactNode } from 'react';
2
+
1
3
  // This utility will add $ at the beginning of the each interface prop
2
4
  // We do that in order to tell styled component to not propagate the given prop down to the dom element
3
5
  // It's called transient props (https://styled-components.com/docs/api#transient-props)
@@ -5,3 +7,31 @@ export type WithTransientProps<T> = { [P in keyof T & string as `$${P}`]: T[P] }
5
7
 
6
8
  export type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
7
9
  export type WithOptional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
10
+
11
+ /**
12
+ * Polymorphic component typing helpers (Pattern B) for the `as`-prop pattern in the
13
+ * UI Component Typing RFC. Only for components that switch their element via `as`;
14
+ * others extend `React.ComponentPropsWithoutRef<'element'>` directly (Pattern A).
15
+ */
16
+
17
+ /** Ref type for element `E`. Conditional `infer`, not `ComponentPropsWithRef<E>['ref']` — indexed access widens to `unknown` for an unbound generic `E`. */
18
+ export type PolymorphicRef<E extends ElementType> = ComponentPropsWithRef<E> extends { ref?: infer R } ? R : never;
19
+
20
+ /** `OwnProps` plus the shared `as` and `children`. */
21
+ type PolymorphicOwnProps<E extends ElementType, OwnProps extends object = object> = OwnProps & {
22
+ as?: E;
23
+ children?: ReactNode;
24
+ };
25
+
26
+ /** Own props + element `E`'s HTML attributes. Own props win via `Omit` (they replace, not merge with, native typing). */
27
+ export type PolymorphicComponentProps<E extends ElementType, OwnProps extends object = object> = PolymorphicOwnProps<
28
+ E,
29
+ OwnProps
30
+ > &
31
+ Omit<ComponentPropsWithoutRef<E>, keyof PolymorphicOwnProps<E, OwnProps>>;
32
+
33
+ /** Adds a `ref` typed for element `E` (React 19: `ref` is a regular prop, no `forwardRef`). */
34
+ export type PolymorphicComponentPropsWithRef<
35
+ E extends ElementType,
36
+ OwnProps extends object = object,
37
+ > = PolymorphicComponentProps<E, OwnProps> & { ref?: PolymorphicRef<E> };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Type-level tests for the polymorphic helpers in `type_utils.ts`, using vitest's built-in
3
+ * `expectTypeOf` (no extra dependency). No runtime assertions — mismatches surface as `tsc`
4
+ * errors, so the existing `type-check` script enforces them. Named `.type-test.ts` (not
5
+ * `.test.ts`) so `vitest run` skips it and Vite leaves it out of the build.
6
+ */
7
+ import { expectTypeOf } from 'vitest';
8
+
9
+ import type { PolymorphicComponentProps, PolymorphicComponentPropsWithRef, PolymorphicRef } from './type_utils';
10
+
11
+ type OwnProps = { variant?: 'a' | 'b' };
12
+ type CustomClick = { onClick: (value: number) => void };
13
+
14
+ // `as` is typed to the element parameter.
15
+ expectTypeOf<PolymorphicComponentProps<'a'>['as']>().toEqualTypeOf<'a' | undefined>();
16
+
17
+ // Element-specific native attributes are present and narrow with `as`.
18
+ expectTypeOf<PolymorphicComponentProps<'a'>>().toHaveProperty('href');
19
+ expectTypeOf<PolymorphicComponentProps<'button'>>().toHaveProperty('type');
20
+ expectTypeOf<PolymorphicComponentProps<'button'>>().not.toHaveProperty('href');
21
+
22
+ // Common attributes are always present regardless of element.
23
+ expectTypeOf<PolymorphicComponentProps<'div'>>().toHaveProperty('aria-label');
24
+ expectTypeOf<PolymorphicComponentProps<'div'>>().toHaveProperty('tabIndex');
25
+
26
+ // Own props merge in and win over native ones via `Omit`.
27
+ expectTypeOf<PolymorphicComponentProps<'div', OwnProps>['variant']>().toEqualTypeOf<'a' | 'b' | undefined>();
28
+ expectTypeOf<PolymorphicComponentProps<'button', CustomClick>['onClick']>().toEqualTypeOf<(value: number) => void>();
29
+
30
+ // The WithRef variant adds `ref`; the plain variant does not.
31
+ expectTypeOf<PolymorphicComponentPropsWithRef<'div'>>().toHaveProperty('ref');
32
+ expectTypeOf<PolymorphicComponentProps<'div'>>().not.toHaveProperty('ref');
33
+
34
+ // `PolymorphicRef` resolves to a concrete (non-`never`) ref type for a bound element.
35
+ expectTypeOf<PolymorphicRef<'a'>>().not.toBeNever();