@apify/ui-library 1.127.9 → 1.128.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 (37) hide show
  1. package/dist/src/components/checkbox/checkbox.js +1 -1
  2. package/dist/src/components/checkbox/checkbox.js.map +1 -1
  3. package/dist/src/components/checkbox/checkbox.style.d.ts.map +1 -1
  4. package/dist/src/components/checkbox/checkbox.style.js +1 -5
  5. package/dist/src/components/checkbox/checkbox.style.js.map +1 -1
  6. package/dist/src/components/collapsible_card/collapsible_card.d.ts +1 -0
  7. package/dist/src/components/collapsible_card/collapsible_card.d.ts.map +1 -1
  8. package/dist/src/components/collapsible_card/collapsible_card.js +3 -3
  9. package/dist/src/components/collapsible_card/collapsible_card.js.map +1 -1
  10. package/dist/src/components/index.d.ts +1 -0
  11. package/dist/src/components/index.d.ts.map +1 -1
  12. package/dist/src/components/index.js +1 -0
  13. package/dist/src/components/index.js.map +1 -1
  14. package/dist/src/components/switch/index.d.ts +2 -0
  15. package/dist/src/components/switch/index.d.ts.map +1 -0
  16. package/dist/src/components/switch/index.js +2 -0
  17. package/dist/src/components/switch/index.js.map +1 -0
  18. package/dist/src/components/switch/switch.d.ts +11 -0
  19. package/dist/src/components/switch/switch.d.ts.map +1 -0
  20. package/dist/src/components/switch/switch.js +25 -0
  21. package/dist/src/components/switch/switch.js.map +1 -0
  22. package/dist/src/components/switch/switch.style.d.ts +2 -0
  23. package/dist/src/components/switch/switch.style.d.ts.map +1 -0
  24. package/dist/src/components/switch/switch.style.js +53 -0
  25. package/dist/src/components/switch/switch.style.js.map +1 -0
  26. package/dist/tsconfig.build.tsbuildinfo +1 -1
  27. package/package.json +3 -2
  28. package/src/components/checkbox/checkbox.stories.tsx +20 -0
  29. package/src/components/checkbox/checkbox.style.ts +1 -5
  30. package/src/components/checkbox/checkbox.tsx +1 -1
  31. package/src/components/collapsible_card/collapsible_card.stories.tsx +16 -0
  32. package/src/components/collapsible_card/collapsible_card.tsx +5 -3
  33. package/src/components/index.ts +1 -0
  34. package/src/components/switch/index.ts +1 -0
  35. package/src/components/switch/switch.stories.jsx +38 -0
  36. package/src/components/switch/switch.style.ts +54 -0
  37. package/src/components/switch/switch.tsx +54 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apify/ui-library",
3
- "version": "1.127.9",
3
+ "version": "1.128.0",
4
4
  "description": "React UI library used by apify.com",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -31,6 +31,7 @@
31
31
  "@floating-ui/react": "^0.26.2",
32
32
  "@radix-ui/react-checkbox": "^1.3.3",
33
33
  "@radix-ui/react-collapsible": "^1.0.0",
34
+ "@radix-ui/react-switch": "^1.2.6",
34
35
  "@react-hook/resize-observer": "^2.0.2",
35
36
  "clsx": "^2.0.0",
36
37
  "dayjs": "1.11.9",
@@ -68,5 +69,5 @@
68
69
  "src",
69
70
  "style"
70
71
  ],
71
- "gitHead": "0b7030cf042943bbd494c7117bc9c104a61641f0"
72
+ "gitHead": "8d4338c49c97cd1491d3522d888054e55036328e"
72
73
  }
@@ -44,6 +44,11 @@ const getIndeterminateLabel = (value: boolean | null) => {
44
44
  return value ? 'Checked' : 'Unchecked';
45
45
  };
46
46
 
47
+ const SectionLabel = styled.div`
48
+ font-weight: bold;
49
+ margin-top: 1rem;
50
+ `;
51
+
47
52
  export const Indeterminate = () => {
48
53
  const [value, setValue] = useState<boolean | null>(null);
49
54
  return (
@@ -52,6 +57,21 @@ export const Indeterminate = () => {
52
57
  <IndeterminateCheckbox value={value} setValue={setValue} />
53
58
  {getIndeterminateLabel(value)} (click to toggle)
54
59
  </Row>
60
+
61
+ <SectionLabel>Indeterminate</SectionLabel>
62
+ <Row><IndeterminateCheckbox value={null} setValue={() => {}} /> Default</Row>
63
+ <Row><IndeterminateCheckbox value={null} setValue={() => {}} disabled /> Disabled</Row>
64
+ <Row><IndeterminateCheckbox value={null} setValue={() => {}} error="Some error" /> Error</Row>
65
+
66
+ <SectionLabel>Checked</SectionLabel>
67
+ <Row><IndeterminateCheckbox value={true} setValue={() => {}} /> Default</Row>
68
+ <Row><IndeterminateCheckbox value={true} setValue={() => {}} disabled /> Disabled</Row>
69
+ <Row><IndeterminateCheckbox value={true} setValue={() => {}} error="Some error" /> Error</Row>
70
+
71
+ <SectionLabel>Unchecked</SectionLabel>
72
+ <Row><IndeterminateCheckbox value={false} setValue={() => {}} /> Default</Row>
73
+ <Row><IndeterminateCheckbox value={false} setValue={() => {}} disabled /> Disabled</Row>
74
+ <Row><IndeterminateCheckbox value={false} setValue={() => {}} error="Some error" /> Error</Row>
55
75
  </Grid>
56
76
  );
57
77
  };
@@ -30,11 +30,7 @@ export const checkboxStyle = css`
30
30
  border-color: ${theme.color.danger.text};
31
31
  }
32
32
 
33
- &.indeterminate {
34
- background-color: ${theme.color.primary.action};
35
- border-color: ${theme.color.primary.action};
36
- }
37
-
33
+ &[data-state="indeterminate"],
38
34
  &[data-state="checked"] {
39
35
  background-color: ${theme.color.primary.action};
40
36
  border-color: ${theme.color.primary.action};
@@ -75,7 +75,7 @@ export const CheckboxPrimitive: FC<CheckboxPrimitiveProps> = (props) => (
75
75
  );
76
76
 
77
77
  export const IndeterminateCheckbox: FC<IndeterminateCheckboxProps> = (props) => (
78
- <InternalCheckbox {...props} className="indeterminate">
78
+ <InternalCheckbox {...props}>
79
79
  {props.value == null ? (
80
80
  <IndeterminateIndicator>
81
81
  <MinusIcon size="12" />
@@ -26,6 +26,10 @@ export default {
26
26
  control: 'boolean',
27
27
  description: 'Whether to hide the chevron icon',
28
28
  },
29
+ noDivider: {
30
+ control: 'boolean',
31
+ description: 'Whether to hide the divider between header and content',
32
+ },
29
33
  topSection: {
30
34
  control: 'text',
31
35
  description: 'Content rendered above the header',
@@ -120,6 +124,18 @@ export const GreyHeaderOnHover: Story = {
120
124
  },
121
125
  };
122
126
 
127
+ /**
128
+ * A collapsible card without the divider between header and content.
129
+ */
130
+ export const NoDivider: Story = {
131
+ args: {
132
+ header: 'No divider between header and content',
133
+ noDivider: true,
134
+ isExpanded: true,
135
+ children: 'This card has no divider line between the header and content areas.',
136
+ },
137
+ };
138
+
123
139
  /**
124
140
  * A collapsible card without the outer border.
125
141
  */
@@ -29,6 +29,7 @@ export type CollapsibleCardProps = {
29
29
  isExpanded?: boolean;
30
30
  onIsExpandedChanged?: (expanded: boolean) => void;
31
31
  noChevron?: boolean;
32
+ noDivider?: boolean;
32
33
  topSection?: ReactNode;
33
34
  isClosedHeaderGrey?: boolean;
34
35
  isHeaderGreyOnHover?: boolean;
@@ -101,8 +102,8 @@ const StyledCardContent = styled.div`
101
102
  overflow: auto;
102
103
  `;
103
104
 
104
- const CollapsibleContent = styled(Collapsible.Content)`
105
- border-top: 1px solid ${theme.color.neutral.border};
105
+ const CollapsibleContent = styled(Collapsible.Content)<{ $noDivider?: boolean }>`
106
+ ${({ $noDivider }) => ($noDivider ? '' : `border-top: 1px solid ${theme.color.neutral.border};`)}
106
107
  `;
107
108
 
108
109
  export const CollapsibleCard: FC<CollapsibleCardProps> = ({
@@ -111,6 +112,7 @@ export const CollapsibleCard: FC<CollapsibleCardProps> = ({
111
112
  isExpanded,
112
113
  onIsExpandedChanged,
113
114
  noChevron,
115
+ noDivider,
114
116
  topSection,
115
117
  hideOuterBorder,
116
118
  hasShadow,
@@ -148,7 +150,7 @@ export const CollapsibleCard: FC<CollapsibleCardProps> = ({
148
150
  <Collapsible.Root
149
151
  open={isUncontrolled ? isOpen : isExpanded}
150
152
  >
151
- <CollapsibleContent className={collapsibleCardClassNames.COLLAPSIBLE_CONTENT_WRAPPER}>
153
+ <CollapsibleContent $noDivider={noDivider} className={collapsibleCardClassNames.COLLAPSIBLE_CONTENT_WRAPPER}>
152
154
  <StyledCardContent className={collapsibleCardClassNames.CONTENT} data-test="card-content">
153
155
  {children}
154
156
  </StyledCardContent>
@@ -28,3 +28,4 @@ export * from './spinner.js';
28
28
  export * from './store/index.js';
29
29
  export * from './checkbox/index.js';
30
30
  export * from './collapsible_card/index.js';
31
+ export * from './switch/index.js';
@@ -0,0 +1 @@
1
+ export * from './switch.js';
@@ -0,0 +1,38 @@
1
+ import { useState } from 'react';
2
+ import styled from 'styled-components';
3
+ import { SwitchPrimitive as Switch } from './switch';
4
+
5
+ export default {
6
+ title: 'UI-Library/Inputs/Switch',
7
+ args: {},
8
+ };
9
+
10
+ const Grid = styled.div`
11
+ margin: 5rem 3rem;
12
+ display: grid;
13
+ grid-template-columns: repeat(2, auto);
14
+ gap: 1rem 5rem;
15
+
16
+ input{
17
+ width: 100%;
18
+ }
19
+ `;
20
+
21
+ export const SwitchPrimitive = () => {
22
+ const [value, setValue] = useState(1);
23
+ return (
24
+ <Grid>
25
+ <Switch value={value} setValue={setValue}/> <p>checked vs unchecked</p>
26
+ <Switch name="Disabled"
27
+ disabled
28
+ value={false}
29
+ setValue={() => {}}
30
+ /> <p>disabled</p>
31
+ <Switch name="Error"
32
+ error='Test error'
33
+ value={value}
34
+ setValue={setValue}
35
+ /> <p>error</p>
36
+ </Grid>
37
+ );
38
+ };
@@ -0,0 +1,54 @@
1
+ import { css } from 'styled-components';
2
+
3
+ import { theme } from '../../design_system/theme.js';
4
+
5
+ export const switchStyle = css`
6
+ width: 32px;
7
+ height: 16px;
8
+ background-color: ${theme.color.neutral.actionSecondary};
9
+ border-radius: 100px;
10
+ position: relative;
11
+ transition: border-color 120ms ease-out, background-color 120ms ease-out !important;
12
+ vertical-align: middle;
13
+
14
+ &:focus-visible {
15
+ outline: 2px solid ${theme.color.primary.fieldBorderActive}!important;
16
+ }
17
+
18
+ &:hover {
19
+ background-color: ${theme.color.neutral.actionSecondaryHover};
20
+ cursor: pointer;
21
+ }
22
+
23
+ &.disabled {
24
+ background-color: ${theme.color.neutral.disabled};
25
+ }
26
+
27
+ &.error {
28
+ background-color: ${theme.color.danger.action};
29
+
30
+ &:hover {
31
+ background-color: ${theme.color.danger.actionHover};
32
+ }
33
+ }
34
+
35
+ &[data-state="checked"] {
36
+ background-color: ${theme.color.success.action};
37
+
38
+ &:hover {
39
+ background-color: ${theme.color.success.actionHover};
40
+ }
41
+
42
+ &.disabled {
43
+ background-color: ${theme.color.success.chipBackground};
44
+ }
45
+
46
+ &.error {
47
+ background-color: ${theme.color.danger.action};
48
+
49
+ &:hover {
50
+ background-color: ${theme.color.danger.actionHover};
51
+ }
52
+ }
53
+ }
54
+ `;
@@ -0,0 +1,54 @@
1
+ import * as SwitchPrimitiveReact from '@radix-ui/react-switch';
2
+ import clsx from 'clsx';
3
+ import styled from 'styled-components';
4
+
5
+ import { theme } from '../../design_system/theme.js';
6
+ import { switchStyle } from './switch.style';
7
+
8
+ const StyledSwitch = styled(SwitchPrimitiveReact.Root)`
9
+ all: unset;
10
+ ${switchStyle}
11
+ `;
12
+
13
+ const StyledThumb = styled(SwitchPrimitiveReact.Thumb)`
14
+ display: block;
15
+ background-color: ${theme.color.neutral.backgroundWhite};
16
+ width: 12px;
17
+ height: 12px;
18
+ border-radius: 100px;
19
+ transition: transform 100ms;
20
+ transform: translateX(2px);
21
+ will-change: transform;
22
+ &[data-state="checked"] {
23
+ transform: translateX(18px);
24
+ }
25
+ `;
26
+ type SwitchPrimitiveProps = {
27
+ value: boolean;
28
+ setValue: (checked: boolean) => void;
29
+ error?: string;
30
+ disabled?: boolean;
31
+ readOnly?: boolean;
32
+ } & Omit<React.ComponentPropsWithoutRef<typeof SwitchPrimitiveReact.Root>, 'checked' | 'onCheckedChange' | 'value'>;
33
+
34
+ export const SwitchPrimitive = ({
35
+ value,
36
+ setValue,
37
+ error,
38
+ disabled,
39
+ readOnly,
40
+ ...rest
41
+ }: SwitchPrimitiveProps) => (
42
+ <StyledSwitch
43
+ {...rest}
44
+ checked={value}
45
+ onCheckedChange={setValue}
46
+ disabled={disabled || readOnly}
47
+ className={clsx(
48
+ error && 'error',
49
+ (disabled || readOnly) && 'disabled',
50
+ )}
51
+ >
52
+ <StyledThumb />
53
+ </StyledSwitch>
54
+ );