@apify/ui-library 1.127.2 → 1.127.4
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.
- package/dist/src/components/checkbox/checkbox.d.ts +18 -0
- package/dist/src/components/checkbox/checkbox.d.ts.map +1 -0
- package/dist/src/components/checkbox/checkbox.js +30 -0
- package/dist/src/components/checkbox/checkbox.js.map +1 -0
- package/dist/src/components/checkbox/checkbox.style.d.ts +2 -0
- package/dist/src/components/checkbox/checkbox.style.d.ts.map +1 -0
- package/dist/src/components/checkbox/checkbox.style.js +61 -0
- package/dist/src/components/checkbox/checkbox.style.js.map +1 -0
- package/dist/src/components/checkbox/index.d.ts +2 -0
- package/dist/src/components/checkbox/index.d.ts.map +1 -0
- package/dist/src/components/checkbox/index.js +2 -0
- package/dist/src/components/checkbox/index.js.map +1 -0
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/src/components/to_consolidate/markdown.js +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/components/checkbox/checkbox.stories.tsx +57 -0
- package/src/components/checkbox/checkbox.style.ts +62 -0
- package/src/components/checkbox/checkbox.tsx +89 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/index.ts +1 -0
- package/src/components/to_consolidate/markdown.tsx +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apify/ui-library",
|
|
3
|
-
"version": "1.127.
|
|
3
|
+
"version": "1.127.4",
|
|
4
4
|
"description": "React UI library used by apify.com",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@apify/ui-icons": "^1.29.1",
|
|
31
31
|
"@floating-ui/react": "^0.26.2",
|
|
32
|
+
"@radix-ui/react-checkbox": "^1.3.3",
|
|
32
33
|
"@react-hook/resize-observer": "^2.0.2",
|
|
33
34
|
"clsx": "^2.0.0",
|
|
34
35
|
"dayjs": "1.11.9",
|
|
@@ -66,5 +67,5 @@
|
|
|
66
67
|
"src",
|
|
67
68
|
"style"
|
|
68
69
|
],
|
|
69
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "63e5464863de833c981f4cca2369aea22b735b53"
|
|
70
71
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type ComponentProps, useState } from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import { CheckboxPrimitive, IndeterminateCheckbox } from './checkbox.js';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Components/Inputs/CheckboxPrimitive',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const Grid = styled.div`
|
|
11
|
+
margin: 5rem 3rem;
|
|
12
|
+
display: grid;
|
|
13
|
+
grid-template-columns: repeat(1, auto);
|
|
14
|
+
gap: 1.4rem;
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
const Row = styled.div`
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
gap: 0.8rem;
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
type ControlledCheckboxProps = { initialValue?: boolean } & Omit<ComponentProps<typeof CheckboxPrimitive>, 'value' | 'setValue'>;
|
|
24
|
+
|
|
25
|
+
const ControlledCheckbox = ({ initialValue = false, ...props }: ControlledCheckboxProps) => {
|
|
26
|
+
const [value, setValue] = useState(initialValue);
|
|
27
|
+
return <CheckboxPrimitive value={value} setValue={setValue} {...props} />;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const States = () => (
|
|
31
|
+
<Grid>
|
|
32
|
+
<Row><ControlledCheckbox /> Unchecked</Row>
|
|
33
|
+
<Row><ControlledCheckbox initialValue /> Checked</Row>
|
|
34
|
+
<Row><ControlledCheckbox disabled /> Disabled</Row>
|
|
35
|
+
<Row><ControlledCheckbox initialValue disabled /> Checked & disabled</Row>
|
|
36
|
+
<Row><ControlledCheckbox readOnly initialValue /> Checked & readonly</Row>
|
|
37
|
+
<Row><ControlledCheckbox error="Some error" /> Error</Row>
|
|
38
|
+
<Row><ControlledCheckbox initialValue error="Some error" /> Checked + error</Row>
|
|
39
|
+
</Grid>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const getIndeterminateLabel = (value: boolean | null) => {
|
|
43
|
+
if (value === null) return 'Indeterminate';
|
|
44
|
+
return value ? 'Checked' : 'Unchecked';
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const Indeterminate = () => {
|
|
48
|
+
const [value, setValue] = useState<boolean | null>(null);
|
|
49
|
+
return (
|
|
50
|
+
<Grid>
|
|
51
|
+
<Row>
|
|
52
|
+
<IndeterminateCheckbox value={value} setValue={setValue} />
|
|
53
|
+
{getIndeterminateLabel(value)} (click to toggle)
|
|
54
|
+
</Row>
|
|
55
|
+
</Grid>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { css } from 'styled-components';
|
|
2
|
+
|
|
3
|
+
import { theme } from '../../design_system/theme.js';
|
|
4
|
+
|
|
5
|
+
export const checkboxStyle = css`
|
|
6
|
+
overflow: hidden;
|
|
7
|
+
border: 1px solid ${theme.color.neutral.border};
|
|
8
|
+
border-radius: ${theme.radius.radius4};
|
|
9
|
+
background-color: ${theme.color.neutral.background};
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
justify-content: center;
|
|
13
|
+
width: 16px;
|
|
14
|
+
height: 16px;
|
|
15
|
+
position: relative;
|
|
16
|
+
box-sizing: border-box;
|
|
17
|
+
transition: border-color 120ms ease-out, background-color 120ms ease-out !important;
|
|
18
|
+
|
|
19
|
+
&:hover, &:focus {
|
|
20
|
+
border-color: ${theme.color.primary.action};
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&.disabled {
|
|
25
|
+
background-color: ${theme.color.neutral.textDisabled};
|
|
26
|
+
border-color: ${theme.color.neutral.border};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&.error {
|
|
30
|
+
border-color: ${theme.color.danger.text};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&.indeterminate {
|
|
34
|
+
background-color: ${theme.color.primary.action};
|
|
35
|
+
border-color: ${theme.color.primary.action};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
&[data-state="checked"] {
|
|
39
|
+
background-color: ${theme.color.primary.action};
|
|
40
|
+
border-color: ${theme.color.primary.action};
|
|
41
|
+
|
|
42
|
+
&:hover {
|
|
43
|
+
background-color: ${theme.color.primary.actionHover};
|
|
44
|
+
border-color: ${theme.color.primary.actionHover};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&.error {
|
|
48
|
+
background-color: ${theme.color.danger.action};
|
|
49
|
+
border-color: ${theme.color.danger.action};
|
|
50
|
+
|
|
51
|
+
&:hover {
|
|
52
|
+
background-color: ${theme.color.danger.actionHover};
|
|
53
|
+
border-color: ${theme.color.danger.actionHover};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&.disabled {
|
|
58
|
+
background-color: ${theme.color.neutral.textDisabled};
|
|
59
|
+
border-color: ${theme.color.neutral.border};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as CheckboxPrimitiveReact from '@radix-ui/react-checkbox';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { type ComponentPropsWithoutRef, type FC } from 'react';
|
|
4
|
+
import styled from 'styled-components';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
CheckIcon, MinusIcon,
|
|
8
|
+
} from '@apify/ui-icons';
|
|
9
|
+
|
|
10
|
+
import { theme } from '../../design_system/theme.js';
|
|
11
|
+
import { checkboxStyle } from './checkbox.style.js';
|
|
12
|
+
|
|
13
|
+
const StyledCheckbox = styled(CheckboxPrimitiveReact.Root)`
|
|
14
|
+
all: unset;
|
|
15
|
+
${checkboxStyle};
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
const StyledIndicator = styled(CheckboxPrimitiveReact.Indicator)`
|
|
19
|
+
color: ${theme.color.neutral.textOnPrimary};
|
|
20
|
+
position: absolute;
|
|
21
|
+
display: flex;
|
|
22
|
+
justify-content: center;
|
|
23
|
+
align-items: center;
|
|
24
|
+
|
|
25
|
+
.disabled & {
|
|
26
|
+
color: ${theme.color.neutral.textMuted};
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
const IndeterminateIndicator = styled(StyledIndicator)`
|
|
31
|
+
color: ${theme.color.neutral.textOnPrimary};
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
type CheckboxBaseProps = Omit<ComponentPropsWithoutRef<typeof CheckboxPrimitiveReact.Root>, 'checked' | 'onCheckedChange' | 'value'> & {
|
|
35
|
+
setValue: (checked: boolean) => void;
|
|
36
|
+
error?: string;
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
readOnly?: boolean;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type CheckboxPrimitiveProps = CheckboxBaseProps & { value: boolean };
|
|
42
|
+
export type IndeterminateCheckboxProps = CheckboxBaseProps & { value: boolean | null };
|
|
43
|
+
|
|
44
|
+
const InternalCheckbox: FC<IndeterminateCheckboxProps> = ({
|
|
45
|
+
children,
|
|
46
|
+
value,
|
|
47
|
+
setValue,
|
|
48
|
+
error,
|
|
49
|
+
disabled,
|
|
50
|
+
readOnly,
|
|
51
|
+
className,
|
|
52
|
+
...rest
|
|
53
|
+
}) => (
|
|
54
|
+
<StyledCheckbox
|
|
55
|
+
{...rest}
|
|
56
|
+
checked={value == null ? 'indeterminate' : value}
|
|
57
|
+
onCheckedChange={setValue}
|
|
58
|
+
disabled={disabled || readOnly}
|
|
59
|
+
className={clsx(
|
|
60
|
+
className,
|
|
61
|
+
error && 'error',
|
|
62
|
+
(disabled || readOnly) && 'disabled',
|
|
63
|
+
)}
|
|
64
|
+
>
|
|
65
|
+
{children}
|
|
66
|
+
</StyledCheckbox>
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
export const CheckboxPrimitive: FC<CheckboxPrimitiveProps> = (props) => (
|
|
70
|
+
<InternalCheckbox {...props}>
|
|
71
|
+
<StyledIndicator>
|
|
72
|
+
<CheckIcon size="12" />
|
|
73
|
+
</StyledIndicator>
|
|
74
|
+
</InternalCheckbox>
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
export const IndeterminateCheckbox: FC<IndeterminateCheckboxProps> = (props) => (
|
|
78
|
+
<InternalCheckbox {...props} className="indeterminate">
|
|
79
|
+
{props.value == null ? (
|
|
80
|
+
<IndeterminateIndicator>
|
|
81
|
+
<MinusIcon size="12" />
|
|
82
|
+
</IndeterminateIndicator>
|
|
83
|
+
) : (
|
|
84
|
+
<StyledIndicator>
|
|
85
|
+
<CheckIcon size="12" />
|
|
86
|
+
</StyledIndicator>
|
|
87
|
+
)}
|
|
88
|
+
</InternalCheckbox>
|
|
89
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './checkbox.js';
|
package/src/components/index.ts
CHANGED
|
@@ -124,7 +124,7 @@ const StyledMarkdownWrapper = styled(Box)<StyledReadmeProps>`
|
|
|
124
124
|
${theme.typography.content.desktop.paragraph}
|
|
125
125
|
}
|
|
126
126
|
a {
|
|
127
|
-
overflow-wrap:
|
|
127
|
+
overflow-wrap: anywhere;
|
|
128
128
|
text-decoration: none;
|
|
129
129
|
&:hover {
|
|
130
130
|
text-decoration: underline;
|