@bento/pressable 0.1.1 → 0.1.3
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/README.md +103 -0
- package/README.mdx +6 -4
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +5 -4
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Pressable
|
|
2
|
+
|
|
3
|
+
The `@bento/pressable` package provides a standardized foundation for interactive elements in the Bento library. It exports the **Pressable** primitive, which provides consistent press interactions and accessibility features for building interactive components.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save @bento/pressable
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Props
|
|
12
|
+
|
|
13
|
+
The `@bento/pressable` package exports the `Pressable` primitive:
|
|
14
|
+
|
|
15
|
+
```jsx
|
|
16
|
+
import { Pressable } from '@bento/pressable';
|
|
17
|
+
|
|
18
|
+
<Pressable onPress={() => console.log('Div pressed!')}>
|
|
19
|
+
<div>Press me</div>
|
|
20
|
+
</Pressable>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The following properties are available to be used on the `Pressable` primitive:
|
|
24
|
+
|
|
25
|
+
| Prop | Type | Required | Description |
|
|
26
|
+
|------|------|----------|------------|
|
|
27
|
+
| `children` | `ReactElement<any, string \| JSXElementConstructor<any>>` | Yes | A single React element that will be made pressable. |
|
|
28
|
+
| `onPress` | `(e: PressEvent) => void` | No | Handler that is called when the pressable is pressed.
|
|
29
|
+
Similar to the standard `onClick` event, but normalized to handle all interaction methods consistently. |
|
|
30
|
+
| `onPressStart` | `(e: PressEvent) => void` | No | Handler that is called when a press interaction starts. |
|
|
31
|
+
| `onPressEnd` | `(e: PressEvent) => void` | No | Handler that is called when a press interaction ends, either
|
|
32
|
+
over the target or when the pointer leaves the target. |
|
|
33
|
+
| `onPressChange` | `(isPressed: boolean) => void` | No | Handler that is called when the press state changes. |
|
|
34
|
+
| `onPressUp` | `(e: PressEvent) => void` | No | Handler that is called when a press is released over the target, regardless of
|
|
35
|
+
whether it started on the target or not. |
|
|
36
|
+
| `slot` | `string` | No | A named part of a component that can be customized. This is implemented by the consuming component.
|
|
37
|
+
The exposed slot names of a component are available in the components documentation. |
|
|
38
|
+
| `slots` | `Record<string, object \| Function>` | No | An object that contains the customizations for the slots.
|
|
39
|
+
The main way you interact with the slot system as a consumer. |
|
|
40
|
+
|
|
41
|
+
For all other properties specified on the `Pressable` primitive, the component will pass them down to the direct child element of the component. Which would be the equivalent of you adding them directly to the child element.
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { Pressable } from '@bento/pressable';
|
|
45
|
+
|
|
46
|
+
function MyComponent() {
|
|
47
|
+
return (
|
|
48
|
+
<Pressable onPress={() => console.log('Pressed!')}>
|
|
49
|
+
<div>Press me</div>
|
|
50
|
+
</Pressable>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Examples
|
|
56
|
+
|
|
57
|
+
#### Basic Div Element
|
|
58
|
+
|
|
59
|
+
The simplest way to use Pressable is to wrap a div element. The component will handle all the necessary accessibility features and interaction states.
|
|
60
|
+
|
|
61
|
+
<Source language='tsx' code={ DivExample } />
|
|
62
|
+
|
|
63
|
+
#### Link Element
|
|
64
|
+
|
|
65
|
+
You can also make link elements pressable while maintaining their semantic meaning and default browser behavior.
|
|
66
|
+
|
|
67
|
+
<Source language='tsx' code={ LinkExample } />
|
|
68
|
+
|
|
69
|
+
#### Custom Component
|
|
70
|
+
|
|
71
|
+
For custom components, you need to forward the ref and pass props to the underlying element to ensure proper functionality.
|
|
72
|
+
|
|
73
|
+
<Source language='tsx' code={ CustomExample } />
|
|
74
|
+
|
|
75
|
+
## Accessibility
|
|
76
|
+
|
|
77
|
+
The Pressable component automatically handles accessibility features:
|
|
78
|
+
|
|
79
|
+
- **Keyboard Navigation**: Supports Enter and Space key activation
|
|
80
|
+
- **Focus Management**: Proper focus handling and focus-visible states
|
|
81
|
+
- **ARIA Attributes**: Automatically applies appropriate ARIA attributes
|
|
82
|
+
- **Screen Reader Support**: Works seamlessly with assistive technologies
|
|
83
|
+
|
|
84
|
+
### Data Attributes
|
|
85
|
+
|
|
86
|
+
The following data attributes are exposed and can be used for styling:
|
|
87
|
+
|
|
88
|
+
| Attribute | Description | Example Values |
|
|
89
|
+
| -------------------- | ------------------------------------------------------- | -------------- |
|
|
90
|
+
| `data-pressed` | Indicates the element is being pressed | "true" |
|
|
91
|
+
| `data-hovered` | Indicates the element is hovered | "true" |
|
|
92
|
+
| `data-focused` | Indicates the element has focus | "true" |
|
|
93
|
+
| `data-focus-visible` | Indicates focus should be visible (keyboard navigation) | "true" |
|
|
94
|
+
|
|
95
|
+
```css
|
|
96
|
+
[data-pressed='true'] {
|
|
97
|
+
background-color: #ccc;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
[data-focus-visible='true'] {
|
|
101
|
+
outline: 2px solid blue;
|
|
102
|
+
}
|
|
103
|
+
```
|
package/README.mdx
CHANGED
|
@@ -79,10 +79,12 @@ The Pressable component automatically handles accessibility features:
|
|
|
79
79
|
|
|
80
80
|
The following data attributes are exposed and can be used for styling:
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
| Attribute | Description | Example Values |
|
|
83
|
+
| -------------------- | ------------------------------------------------------- | -------------- |
|
|
84
|
+
| `data-pressed` | Indicates the element is being pressed | "true" |
|
|
85
|
+
| `data-hovered` | Indicates the element is hovered | "true" |
|
|
86
|
+
| `data-focused` | Indicates the element has focus | "true" |
|
|
87
|
+
| `data-focus-visible` | Indicates focus should be visible (keyboard navigation) | "true" |
|
|
86
88
|
|
|
87
89
|
```css
|
|
88
90
|
[data-pressed='true'] {
|
package/dist/index.d.cts
CHANGED
|
@@ -39,6 +39,6 @@ interface PressableProps extends PressProps, Omit<HTMLAttributes<HTMLElement>, k
|
|
|
39
39
|
* </Pressable>
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
declare const Pressable: React.
|
|
42
|
+
declare const Pressable: React.MemoExoticComponent<React.ComponentType<PressableProps & _bento_slots.Slots>>;
|
|
43
43
|
|
|
44
44
|
export { Pressable, type PressableProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -39,6 +39,6 @@ interface PressableProps extends PressProps, Omit<HTMLAttributes<HTMLElement>, k
|
|
|
39
39
|
* </Pressable>
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
declare const Pressable: React.
|
|
42
|
+
declare const Pressable: React.MemoExoticComponent<React.ComponentType<PressableProps & _bento_slots.Slots>>;
|
|
43
43
|
|
|
44
44
|
export { Pressable, type PressableProps };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bento/pressable",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Pressable primitive provides consistent press interactions and accessibility features for building interactive components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"build": "tsup-node",
|
|
10
10
|
"lint": "biome lint && tsc",
|
|
11
11
|
"posttest": "npm run lint",
|
|
12
|
+
"prepublishOnly": "node ../../scripts/compile-readme.ts",
|
|
12
13
|
"pretest": "npm run build",
|
|
13
14
|
"test": "vitest --run",
|
|
14
15
|
"test:watch": "vitest"
|
|
@@ -39,9 +40,9 @@
|
|
|
39
40
|
"package.json"
|
|
40
41
|
],
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"@bento/slots": "^0.
|
|
43
|
-
"@bento/use-data-attributes": "^0.1.
|
|
44
|
-
"@bento/use-props": "^0.
|
|
43
|
+
"@bento/slots": "^0.2.0",
|
|
44
|
+
"@bento/use-data-attributes": "^0.1.1",
|
|
45
|
+
"@bento/use-props": "^0.2.0",
|
|
45
46
|
"@react-aria/utils": "^3.30.0",
|
|
46
47
|
"react-aria": "^3.44.0"
|
|
47
48
|
},
|