@bento/pressable 0.1.1 → 0.1.2

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 (2) hide show
  1. package/README.md +101 -0
  2. package/package.json +5 -4
package/README.md ADDED
@@ -0,0 +1,101 @@
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
+ - `data-pressed` - True when the button is being pressed
89
+ - `data-hovered` - True when the button is hovered
90
+ - `data-focused` - True when the button has focus
91
+ - `data-focus-visible` - True when focus should be visible (keyboard navigation)
92
+
93
+ ```css
94
+ [data-pressed='true'] {
95
+ background-color: #ccc;
96
+ }
97
+
98
+ [data-focus-visible='true'] {
99
+ outline: 2px solid blue;
100
+ }
101
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bento/pressable",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
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.1.1",
43
- "@bento/use-data-attributes": "^0.1.0",
44
- "@bento/use-props": "^0.1.0",
43
+ "@bento/slots": "^0.1.3",
44
+ "@bento/use-data-attributes": "^0.1.1",
45
+ "@bento/use-props": "^0.1.1",
45
46
  "@react-aria/utils": "^3.30.0",
46
47
  "react-aria": "^3.44.0"
47
48
  },