ugly-app 0.1.1098 → 0.1.1099
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/cli/version.d.ts +1 -1
- package/dist/cli/version.js +1 -1
- package/dist/client/components/Pressable.d.ts +3 -4
- package/dist/client/components/Pressable.d.ts.map +1 -1
- package/dist/client/components/Pressable.js +2 -2
- package/dist/client/components/Pressable.js.map +1 -1
- package/dist/client/components/Pressable.test.d.ts +2 -0
- package/dist/client/components/Pressable.test.d.ts.map +1 -0
- package/dist/client/components/Pressable.test.js +79 -0
- package/dist/client/components/Pressable.test.js.map +1 -0
- package/package.json +1 -1
- package/src/cli/version.ts +1 -1
- package/src/client/components/Pressable.test.tsx +137 -0
- package/src/client/components/Pressable.tsx +6 -4
package/dist/cli/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const CLI_VERSION = "0.1.
|
|
1
|
+
export declare const CLI_VERSION = "0.1.1099";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/cli/version.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CSSProperties, ElementType, MouseEvent, ReactElement, ReactNode } from 'react';
|
|
2
|
-
export interface PressableProps {
|
|
1
|
+
import type { AriaAttributes, CSSProperties, ElementType, MouseEvent, ReactElement, ReactNode } from 'react';
|
|
2
|
+
export interface PressableProps extends AriaAttributes {
|
|
3
3
|
'children'?: ReactNode;
|
|
4
4
|
'onPress'?: () => void;
|
|
5
5
|
'onContextMenu'?: (e: MouseEvent) => void;
|
|
@@ -9,7 +9,6 @@ export interface PressableProps {
|
|
|
9
9
|
'style'?: CSSProperties;
|
|
10
10
|
'as'?: ElementType;
|
|
11
11
|
'data-id'?: string;
|
|
12
|
-
'aria-label'?: string;
|
|
13
12
|
}
|
|
14
|
-
export declare function Pressable({ children, onPress, onContextMenu, href, disabled, activeOpacity, style, as, 'data-id': dataId,
|
|
13
|
+
export declare function Pressable({ children, onPress, onContextMenu, href, disabled, activeOpacity, style, as, 'data-id': dataId, ...ariaProps }: PressableProps): ReactElement;
|
|
15
14
|
//# sourceMappingURL=Pressable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pressable.d.ts","sourceRoot":"","sources":["../../../src/client/components/Pressable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,UAAU,EACV,YAAY,EACZ,SAAS,EACV,MAAM,OAAO,CAAC;AAGf,MAAM,WAAW,cAAc;
|
|
1
|
+
{"version":3,"file":"Pressable.d.ts","sourceRoot":"","sources":["../../../src/client/components/Pressable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,WAAW,EACX,UAAU,EACV,YAAY,EACZ,SAAS,EACV,MAAM,OAAO,CAAC;AAGf,MAAM,WAAW,cAAe,SAAQ,cAAc;IACpD,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,eAAe,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,OAAO,EACP,aAAa,EACb,IAAI,EACJ,QAAgB,EAChB,aAAmB,EACnB,KAAK,EACL,EAAE,EACF,SAAS,EAAE,MAAM,EACjB,GAAG,SAAS,EACb,EAAE,cAAc,GAAG,YAAY,CA4B/B"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
-
export function Pressable({ children, onPress, onContextMenu, href, disabled = false, activeOpacity = 0.5, style, as, 'data-id': dataId,
|
|
3
|
+
export function Pressable({ children, onPress, onContextMenu, href, disabled = false, activeOpacity = 0.5, style, as, 'data-id': dataId, ...ariaProps }) {
|
|
4
4
|
const [pressed, setPressed] = useState(false);
|
|
5
5
|
const Tag = as ?? (href ? 'a' : 'div');
|
|
6
|
-
return (_jsx(Tag, { href: Tag === 'a' ? href : undefined, onClick: disabled ? undefined : onPress, onContextMenu: onContextMenu, onMouseDown: () => setPressed(true), onMouseUp: () => setPressed(false), onMouseLeave: () => setPressed(false), "data-id": dataId,
|
|
6
|
+
return (_jsx(Tag, { ...ariaProps, href: Tag === 'a' ? href : undefined, type: Tag === 'button' ? 'button' : undefined, disabled: Tag === 'button' ? disabled : undefined, onClick: disabled ? undefined : onPress, onContextMenu: onContextMenu, onMouseDown: () => setPressed(true), onMouseUp: () => setPressed(false), onMouseLeave: () => setPressed(false), "data-id": dataId, role: !href && onPress && Tag !== 'button' ? 'button' : undefined, style: {
|
|
7
7
|
cursor: disabled ? 'not-allowed' : 'pointer',
|
|
8
8
|
userSelect: 'none',
|
|
9
9
|
transition: 'opacity 100ms',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pressable.js","sourceRoot":"","sources":["../../../src/client/components/Pressable.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"Pressable.js","sourceRoot":"","sources":["../../../src/client/components/Pressable.tsx"],"names":[],"mappings":";AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAcjC,MAAM,UAAU,SAAS,CAAC,EACxB,QAAQ,EACR,OAAO,EACP,aAAa,EACb,IAAI,EACJ,QAAQ,GAAG,KAAK,EAChB,aAAa,GAAG,GAAG,EACnB,KAAK,EACL,EAAE,EACF,SAAS,EAAE,MAAM,EACjB,GAAG,SAAS,EACG;IACf,MAAM,CAAC,OAAO,EAAE,UA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version":3,"file":"Pressable.test.d.ts","sourceRoot":"","sources":["../../../src/client/components/Pressable.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// @vitest-environment jsdom
|
|
3
|
+
import { act, cleanup, fireEvent, render } from '@testing-library/react';
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { Pressable } from './Pressable.js';
|
|
6
|
+
afterEach(cleanup);
|
|
7
|
+
describe('Pressable native buttons', () => {
|
|
8
|
+
it('forwards ARIA state and updates it when controlled props change', () => {
|
|
9
|
+
const { getByRole, rerender } = render(_jsx(Pressable, { as: "button", "aria-label": "Choose manual reading", "aria-pressed": false, "aria-describedby": "explanation", "data-id": "reading-mode", children: "Manual" }));
|
|
10
|
+
const button = getByRole('button', { name: 'Choose manual reading' });
|
|
11
|
+
expect(button.getAttribute('aria-pressed')).toBe('false');
|
|
12
|
+
expect(button.getAttribute('aria-describedby')).toBe('explanation');
|
|
13
|
+
expect(button.getAttribute('data-id')).toBe('reading-mode');
|
|
14
|
+
rerender(_jsx(Pressable, { as: "button", "aria-label": "Choose manual reading", "aria-pressed": true, children: "Manual" }));
|
|
15
|
+
expect(button.getAttribute('aria-pressed')).toBe('true');
|
|
16
|
+
expect(button.hasAttribute('aria-describedby')).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
it('uses a non-submitting native button and suppresses activation when disabled', () => {
|
|
19
|
+
const onPress = vi.fn();
|
|
20
|
+
const onSubmit = vi.fn((event) => event.preventDefault());
|
|
21
|
+
const { getByRole, rerender } = render(_jsx("form", { onSubmit: onSubmit, children: _jsx(Pressable, { as: "button", onPress: onPress, disabled: true, children: "Choose" }) }));
|
|
22
|
+
const button = getByRole('button');
|
|
23
|
+
expect(button.type).toBe('button');
|
|
24
|
+
expect(button.disabled).toBe(true);
|
|
25
|
+
act(() => button.click());
|
|
26
|
+
expect(onPress).not.toHaveBeenCalled();
|
|
27
|
+
expect(onSubmit).not.toHaveBeenCalled();
|
|
28
|
+
rerender(_jsx("form", { onSubmit: onSubmit, children: _jsx(Pressable, { as: "button", onPress: onPress, children: "Choose" }) }));
|
|
29
|
+
expect(button.disabled).toBe(false);
|
|
30
|
+
act(() => button.click());
|
|
31
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
32
|
+
expect(onSubmit).not.toHaveBeenCalled();
|
|
33
|
+
});
|
|
34
|
+
it('does not synthesize activation from native-button key events', () => {
|
|
35
|
+
const onPress = vi.fn();
|
|
36
|
+
const { getByRole } = render(_jsx(Pressable, { as: "button", onPress: onPress, children: "Choose" }));
|
|
37
|
+
const button = getByRole('button');
|
|
38
|
+
for (const key of ['Enter', ' ']) {
|
|
39
|
+
expect(fireEvent.keyDown(button, { key })).toBe(true);
|
|
40
|
+
expect(fireEvent.keyUp(button, { key })).toBe(true);
|
|
41
|
+
}
|
|
42
|
+
expect(onPress).not.toHaveBeenCalled();
|
|
43
|
+
// jsdom does not perform browser keyboard default activation. Dispatch its
|
|
44
|
+
// resulting click explicitly: the component handles that click exactly once.
|
|
45
|
+
act(() => button.click());
|
|
46
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe('Pressable existing rendering', () => {
|
|
50
|
+
it('preserves link props, context menu and mouse pressed opacity', () => {
|
|
51
|
+
const onPress = vi.fn();
|
|
52
|
+
const onContextMenu = vi.fn();
|
|
53
|
+
const { getByRole } = render(_jsx(Pressable, { href: "/book", onPress: onPress, onContextMenu: onContextMenu, activeOpacity: 0.3, style: { color: 'red' }, "aria-label": "Open book", children: "Book" }));
|
|
54
|
+
const link = getByRole('link', { name: 'Open book' });
|
|
55
|
+
expect(link.getAttribute('href')).toBe('/book');
|
|
56
|
+
expect(link.hasAttribute('type')).toBe(false);
|
|
57
|
+
expect(link.hasAttribute('disabled')).toBe(false);
|
|
58
|
+
expect(link.style.opacity).toBe('1');
|
|
59
|
+
fireEvent.mouseDown(link);
|
|
60
|
+
expect(link.style.opacity).toBe('0.3');
|
|
61
|
+
fireEvent.mouseUp(link);
|
|
62
|
+
expect(link.style.opacity).toBe('1');
|
|
63
|
+
fireEvent.mouseDown(link);
|
|
64
|
+
fireEvent.mouseLeave(link);
|
|
65
|
+
expect(link.style.opacity).toBe('1');
|
|
66
|
+
expect(link.style.color).toBe('red');
|
|
67
|
+
fireEvent.contextMenu(link);
|
|
68
|
+
expect(onContextMenu).toHaveBeenCalledTimes(1);
|
|
69
|
+
});
|
|
70
|
+
it('preserves an explicit custom tag and forwards its ARIA attributes', () => {
|
|
71
|
+
const { getByRole } = render(_jsx(Pressable, { as: "section", onPress: () => { }, "aria-label": "Custom action", "aria-expanded": false, children: "Custom" }));
|
|
72
|
+
const custom = getByRole('button', { name: 'Custom action' });
|
|
73
|
+
expect(custom.tagName).toBe('SECTION');
|
|
74
|
+
expect(custom.getAttribute('aria-expanded')).toBe('false');
|
|
75
|
+
expect(custom.hasAttribute('type')).toBe(false);
|
|
76
|
+
expect(custom.hasAttribute('disabled')).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=Pressable.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pressable.test.js","sourceRoot":"","sources":["../../../src/client/components/Pressable.test.tsx"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,SAAS,CAAC,OAAO,CAAC,CAAC;AAEnB,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,EAAE,CAAC,iEAAiE,EAA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Q,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC,CAAC;QAC9D,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3D,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAChD,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ugly-app",
|
|
3
3
|
"packageManager": "pnpm@10.34.5",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.1099",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"comment:files": "Allowlist what ships to npm. dist = runtime; src = sourcemap targets (dist/*.js.map reference ../../src/); templates = CLI scaffold. Everything else at repo root (.pgdata local Postgres, coverage, assets/icons sources, test/, test-results/) is excluded by omission. The !negations strip the scaffold's installed deps + cruft (templates/node_modules is 200MB+ and must never ship). package.json/README/LICENSE ship automatically.",
|
|
7
7
|
"files": [
|
package/src/cli/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Auto-generated by prebuild — do not edit manually
|
|
2
|
-
export const CLI_VERSION = "0.1.
|
|
2
|
+
export const CLI_VERSION = "0.1.1099";
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { act, cleanup, fireEvent, render } from '@testing-library/react';
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { Pressable } from './Pressable.js';
|
|
5
|
+
|
|
6
|
+
afterEach(cleanup);
|
|
7
|
+
|
|
8
|
+
describe('Pressable native buttons', () => {
|
|
9
|
+
it('forwards ARIA state and updates it when controlled props change', () => {
|
|
10
|
+
const { getByRole, rerender } = render(
|
|
11
|
+
<Pressable
|
|
12
|
+
as="button"
|
|
13
|
+
aria-label="Choose manual reading"
|
|
14
|
+
aria-pressed={false}
|
|
15
|
+
aria-describedby="explanation"
|
|
16
|
+
data-id="reading-mode"
|
|
17
|
+
>
|
|
18
|
+
Manual
|
|
19
|
+
</Pressable>,
|
|
20
|
+
);
|
|
21
|
+
const button = getByRole('button', { name: 'Choose manual reading' });
|
|
22
|
+
expect(button.getAttribute('aria-pressed')).toBe('false');
|
|
23
|
+
expect(button.getAttribute('aria-describedby')).toBe('explanation');
|
|
24
|
+
expect(button.getAttribute('data-id')).toBe('reading-mode');
|
|
25
|
+
rerender(
|
|
26
|
+
<Pressable
|
|
27
|
+
as="button"
|
|
28
|
+
aria-label="Choose manual reading"
|
|
29
|
+
aria-pressed={true}
|
|
30
|
+
>
|
|
31
|
+
Manual
|
|
32
|
+
</Pressable>,
|
|
33
|
+
);
|
|
34
|
+
expect(button.getAttribute('aria-pressed')).toBe('true');
|
|
35
|
+
expect(button.hasAttribute('aria-describedby')).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('uses a non-submitting native button and suppresses activation when disabled', () => {
|
|
39
|
+
const onPress = vi.fn();
|
|
40
|
+
const onSubmit = vi.fn((event) => event.preventDefault());
|
|
41
|
+
const { getByRole, rerender } = render(
|
|
42
|
+
<form onSubmit={onSubmit}>
|
|
43
|
+
<Pressable as="button" onPress={onPress} disabled>
|
|
44
|
+
Choose
|
|
45
|
+
</Pressable>
|
|
46
|
+
</form>,
|
|
47
|
+
);
|
|
48
|
+
const button = getByRole('button') as HTMLButtonElement;
|
|
49
|
+
expect(button.type).toBe('button');
|
|
50
|
+
expect(button.disabled).toBe(true);
|
|
51
|
+
act(() => button.click());
|
|
52
|
+
expect(onPress).not.toHaveBeenCalled();
|
|
53
|
+
expect(onSubmit).not.toHaveBeenCalled();
|
|
54
|
+
rerender(
|
|
55
|
+
<form onSubmit={onSubmit}>
|
|
56
|
+
<Pressable as="button" onPress={onPress}>
|
|
57
|
+
Choose
|
|
58
|
+
</Pressable>
|
|
59
|
+
</form>,
|
|
60
|
+
);
|
|
61
|
+
expect(button.disabled).toBe(false);
|
|
62
|
+
act(() => button.click());
|
|
63
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
64
|
+
expect(onSubmit).not.toHaveBeenCalled();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('does not synthesize activation from native-button key events', () => {
|
|
68
|
+
const onPress = vi.fn();
|
|
69
|
+
const { getByRole } = render(
|
|
70
|
+
<Pressable as="button" onPress={onPress}>
|
|
71
|
+
Choose
|
|
72
|
+
</Pressable>,
|
|
73
|
+
);
|
|
74
|
+
const button = getByRole('button');
|
|
75
|
+
for (const key of ['Enter', ' ']) {
|
|
76
|
+
expect(fireEvent.keyDown(button, { key })).toBe(true);
|
|
77
|
+
expect(fireEvent.keyUp(button, { key })).toBe(true);
|
|
78
|
+
}
|
|
79
|
+
expect(onPress).not.toHaveBeenCalled();
|
|
80
|
+
// jsdom does not perform browser keyboard default activation. Dispatch its
|
|
81
|
+
// resulting click explicitly: the component handles that click exactly once.
|
|
82
|
+
act(() => button.click());
|
|
83
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('Pressable existing rendering', () => {
|
|
88
|
+
it('preserves link props, context menu and mouse pressed opacity', () => {
|
|
89
|
+
const onPress = vi.fn();
|
|
90
|
+
const onContextMenu = vi.fn();
|
|
91
|
+
const { getByRole } = render(
|
|
92
|
+
<Pressable
|
|
93
|
+
href="/book"
|
|
94
|
+
onPress={onPress}
|
|
95
|
+
onContextMenu={onContextMenu}
|
|
96
|
+
activeOpacity={0.3}
|
|
97
|
+
style={{ color: 'red' }}
|
|
98
|
+
aria-label="Open book"
|
|
99
|
+
>
|
|
100
|
+
Book
|
|
101
|
+
</Pressable>,
|
|
102
|
+
);
|
|
103
|
+
const link = getByRole('link', { name: 'Open book' });
|
|
104
|
+
expect(link.getAttribute('href')).toBe('/book');
|
|
105
|
+
expect(link.hasAttribute('type')).toBe(false);
|
|
106
|
+
expect(link.hasAttribute('disabled')).toBe(false);
|
|
107
|
+
expect(link.style.opacity).toBe('1');
|
|
108
|
+
fireEvent.mouseDown(link);
|
|
109
|
+
expect(link.style.opacity).toBe('0.3');
|
|
110
|
+
fireEvent.mouseUp(link);
|
|
111
|
+
expect(link.style.opacity).toBe('1');
|
|
112
|
+
fireEvent.mouseDown(link);
|
|
113
|
+
fireEvent.mouseLeave(link);
|
|
114
|
+
expect(link.style.opacity).toBe('1');
|
|
115
|
+
expect(link.style.color).toBe('red');
|
|
116
|
+
fireEvent.contextMenu(link);
|
|
117
|
+
expect(onContextMenu).toHaveBeenCalledTimes(1);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('preserves an explicit custom tag and forwards its ARIA attributes', () => {
|
|
121
|
+
const { getByRole } = render(
|
|
122
|
+
<Pressable
|
|
123
|
+
as="section"
|
|
124
|
+
onPress={() => {}}
|
|
125
|
+
aria-label="Custom action"
|
|
126
|
+
aria-expanded={false}
|
|
127
|
+
>
|
|
128
|
+
Custom
|
|
129
|
+
</Pressable>,
|
|
130
|
+
);
|
|
131
|
+
const custom = getByRole('button', { name: 'Custom action' });
|
|
132
|
+
expect(custom.tagName).toBe('SECTION');
|
|
133
|
+
expect(custom.getAttribute('aria-expanded')).toBe('false');
|
|
134
|
+
expect(custom.hasAttribute('type')).toBe(false);
|
|
135
|
+
expect(custom.hasAttribute('disabled')).toBe(false);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
AriaAttributes,
|
|
2
3
|
CSSProperties,
|
|
3
4
|
ElementType,
|
|
4
5
|
MouseEvent,
|
|
@@ -7,7 +8,7 @@ import type {
|
|
|
7
8
|
} from 'react';
|
|
8
9
|
import { useState } from 'react';
|
|
9
10
|
|
|
10
|
-
export interface PressableProps {
|
|
11
|
+
export interface PressableProps extends AriaAttributes {
|
|
11
12
|
'children'?: ReactNode;
|
|
12
13
|
'onPress'?: () => void;
|
|
13
14
|
'onContextMenu'?: (e: MouseEvent) => void;
|
|
@@ -17,7 +18,6 @@ export interface PressableProps {
|
|
|
17
18
|
'style'?: CSSProperties;
|
|
18
19
|
'as'?: ElementType;
|
|
19
20
|
'data-id'?: string;
|
|
20
|
-
'aria-label'?: string;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export function Pressable({
|
|
@@ -30,21 +30,23 @@ export function Pressable({
|
|
|
30
30
|
style,
|
|
31
31
|
as,
|
|
32
32
|
'data-id': dataId,
|
|
33
|
-
|
|
33
|
+
...ariaProps
|
|
34
34
|
}: PressableProps): ReactElement {
|
|
35
35
|
const [pressed, setPressed] = useState(false);
|
|
36
36
|
const Tag: ElementType = as ?? (href ? 'a' : 'div');
|
|
37
37
|
|
|
38
38
|
return (
|
|
39
39
|
<Tag
|
|
40
|
+
{...ariaProps}
|
|
40
41
|
href={Tag === 'a' ? href : undefined}
|
|
42
|
+
type={Tag === 'button' ? 'button' : undefined}
|
|
43
|
+
disabled={Tag === 'button' ? disabled : undefined}
|
|
41
44
|
onClick={disabled ? undefined : onPress}
|
|
42
45
|
onContextMenu={onContextMenu}
|
|
43
46
|
onMouseDown={() => setPressed(true)}
|
|
44
47
|
onMouseUp={() => setPressed(false)}
|
|
45
48
|
onMouseLeave={() => setPressed(false)}
|
|
46
49
|
data-id={dataId}
|
|
47
|
-
aria-label={ariaLabel}
|
|
48
50
|
role={!href && onPress && Tag !== 'button' ? 'button' : undefined}
|
|
49
51
|
style={{
|
|
50
52
|
cursor: disabled ? 'not-allowed' : 'pointer',
|