@asnewyla/card 0.2.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 XD
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @asnewyla/card
2
+
3
+ Content card surface with an optional full-bleed image, padding, and radius.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @asnewyla/card @asnewyla/image
9
+ ```
10
+
11
+ `Card` renders `@asnewyla/image`'s `Image` internally for its optional `image`
12
+ slot, so that stylesheet also needs importing once, alongside `Card`'s own:
13
+
14
+ ```ts
15
+ import '@asnewyla/card/styles.css';
16
+ import '@asnewyla/image/styles.css';
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```tsx
22
+ import { Card } from '@asnewyla/card';
23
+
24
+ <Card>
25
+ <h3>Card title</h3>
26
+ <p>Some supporting body text.</p>
27
+ </Card>
28
+
29
+ <Card
30
+ radius="md"
31
+ image={{ src: '/photo.jpg', alt: 'A mountain at sunset', aspectRatio: '2 / 1' }}
32
+ >
33
+ <h3>Mountain view</h3>
34
+ <p>The image renders full-bleed above the content, clipped to the card's own radius.</p>
35
+ </Card>
36
+ ```
37
+
38
+ ### Props
39
+
40
+ | Prop | Type | Default |
41
+ |---|---|---|
42
+ | `children` | `React.ReactNode` (**required**) | — |
43
+ | `image` | `Omit<ImageProps, 'radius'>` | — |
44
+ | `padding` | `'sm' \| 'md' \| 'lg'` | `'md'` |
45
+ | `radius` | `'sm' \| 'md' \| 'lg' \| 'full'` | — (square corners) |
46
+
47
+ Every other native `<div>` prop (`className`, `style`, `id`, `aria-*`, ...) is
48
+ accepted and forwarded to the root element; a `className` you pass is merged
49
+ with the card's own, not replaced.
50
+
51
+ `image` accepts everything `Image` itself does — `src`, `alt`, `fit`,
52
+ `aspectRatio`, `fallback`, native `<img>` attributes — except `radius`:
53
+ the card's own `radius` already governs the image's corners (it's rendered
54
+ edge-to-edge and clipped to the card's shape), so a separate image radius
55
+ would just be a way to fight it.
56
+
57
+ ### Theming
58
+
59
+ Override the CSS custom properties — defaults adapt automatically to
60
+ `prefers-color-scheme` via `@asnewyla/tokens`:
61
+
62
+ ```css
63
+ :root {
64
+ --xd-color-border: #cbd5e1;
65
+ --xd-radius-md: 0.375rem;
66
+ --xd-space-md: 0.5rem;
67
+ }
68
+ ```
69
+
70
+ ## License
71
+
72
+ MIT
package/dist/index.css ADDED
@@ -0,0 +1,37 @@
1
+ /* src/components/Card.css */
2
+ .xd-card {
3
+ display: flex;
4
+ flex-direction: column;
5
+ overflow: hidden;
6
+ border: var(--xd-border-width-thin, 1px) solid var(--xd-color-border, #cbd5e1);
7
+ }
8
+ .xd-card[data-padding=sm] {
9
+ --_padding: var(--xd-space-sm, 0.375rem);
10
+ }
11
+ .xd-card[data-padding=md] {
12
+ --_padding: var(--xd-space-md, 0.5rem);
13
+ }
14
+ .xd-card[data-padding=lg] {
15
+ --_padding: var(--xd-space-lg, 0.75rem);
16
+ }
17
+ .xd-card {
18
+ padding: var(--_padding);
19
+ }
20
+ .xd-card > .xd-image {
21
+ margin: calc(var(--_padding) * -1) calc(var(--_padding) * -1) var(--_padding);
22
+ width: calc(100% + var(--_padding) * 2);
23
+ max-width: none;
24
+ }
25
+ .xd-card[data-radius=sm] {
26
+ border-radius: var(--xd-radius-sm, 0.25rem);
27
+ }
28
+ .xd-card[data-radius=md] {
29
+ border-radius: var(--xd-radius-md, 0.375rem);
30
+ }
31
+ .xd-card[data-radius=lg] {
32
+ border-radius: var(--xd-radius-lg, 0.625rem);
33
+ }
34
+ .xd-card[data-radius=full] {
35
+ border-radius: var(--xd-radius-full, 9999px);
36
+ }
37
+ /*# sourceMappingURL=index.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/Card.css"],"sourcesContent":[".xd-card {\r\n display: flex;\r\n flex-direction: column;\r\n overflow: hidden;\r\n border: var(--xd-border-width-thin, 1px) solid var(--xd-color-border, #cbd5e1);\r\n}\r\n\r\n/* --- Padding --- */\r\n\r\n.xd-card[data-padding=\"sm\"] {\r\n --_padding: var(--xd-space-sm, 0.375rem);\r\n}\r\n\r\n.xd-card[data-padding=\"md\"] {\r\n --_padding: var(--xd-space-md, 0.5rem);\r\n}\r\n\r\n.xd-card[data-padding=\"lg\"] {\r\n --_padding: var(--xd-space-lg, 0.75rem);\r\n}\r\n\r\n.xd-card {\r\n padding: var(--_padding);\r\n}\r\n\r\n/* The image is pulled back out to the card's edges via a negative margin\r\n matching --_padding, then re-clipped to the card's own border-radius by\r\n `overflow: hidden` above — no separate image radius needed. */\r\n.xd-card > .xd-image {\r\n margin: calc(var(--_padding) * -1) calc(var(--_padding) * -1) var(--_padding);\r\n width: calc(100% + var(--_padding) * 2);\r\n max-width: none;\r\n}\r\n\r\n/* --- Radius --- */\r\n\r\n.xd-card[data-radius=\"sm\"] {\r\n border-radius: var(--xd-radius-sm, 0.25rem);\r\n}\r\n\r\n.xd-card[data-radius=\"md\"] {\r\n border-radius: var(--xd-radius-md, 0.375rem);\r\n}\r\n\r\n.xd-card[data-radius=\"lg\"] {\r\n border-radius: var(--xd-radius-lg, 0.625rem);\r\n}\r\n\r\n.xd-card[data-radius=\"full\"] {\r\n border-radius: var(--xd-radius-full, 9999px);\r\n}\r\n"],"mappings":";AAAA,CAAC;AACC,WAAS;AACT,kBAAgB;AAChB,YAAU;AACV,UAAQ,IAAI,sBAAsB,EAAE,KAAK,MAAM,IAAI,iBAAiB,EAAE;AACxE;AAIA,CATC,OASO,CAAC;AACP,cAAY,IAAI,aAAa,EAAE;AACjC;AAEA,CAbC,OAaO,CAAC;AACP,cAAY,IAAI,aAAa,EAAE;AACjC;AAEA,CAjBC,OAiBO,CAAC;AACP,cAAY,IAAI,aAAa,EAAE;AACjC;AAEA,CArBC;AAsBC,WAAS,IAAI;AACf;AAKA,CA5BC,QA4BQ,EAAE,CAAC;AACV,UAAQ,KAAK,IAAI,YAAY,EAAE,IAAI,KAAK,IAAI,YAAY,EAAE,IAAI,IAAI;AAClE,SAAO,KAAK,KAAK,EAAE,IAAI,YAAY,EAAE;AACrC,aAAW;AACb;AAIA,CApCC,OAoCO,CAAC;AACP,iBAAe,IAAI,cAAc,EAAE;AACrC;AAEA,CAxCC,OAwCO,CAAC;AACP,iBAAe,IAAI,cAAc,EAAE;AACrC;AAEA,CA5CC,OA4CO,CAAC;AACP,iBAAe,IAAI,cAAc,EAAE;AACrC;AAEA,CAhDC,OAgDO,CAAC;AACP,iBAAe,IAAI,gBAAgB,EAAE;AACvC;","names":[]}
@@ -0,0 +1,20 @@
1
+ import * as react from 'react';
2
+ import { ReactNode, ComponentPropsWithoutRef } from 'react';
3
+ import { ImageProps } from '@asnewyla/image';
4
+
5
+ type CardPadding = 'sm' | 'md' | 'lg';
6
+ type CardRadius = 'sm' | 'md' | 'lg' | 'full';
7
+ type CardProps = ComponentPropsWithoutRef<'div'> & {
8
+ children: ReactNode;
9
+ image?: Omit<ImageProps, 'radius'>;
10
+ padding?: CardPadding;
11
+ radius?: CardRadius;
12
+ };
13
+ declare const Card: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
14
+ children: ReactNode;
15
+ image?: Omit<ImageProps, "radius">;
16
+ padding?: CardPadding;
17
+ radius?: CardRadius;
18
+ } & react.RefAttributes<HTMLDivElement>>;
19
+
20
+ export { Card, type CardPadding, type CardProps, type CardRadius };
@@ -0,0 +1,20 @@
1
+ import * as react from 'react';
2
+ import { ReactNode, ComponentPropsWithoutRef } from 'react';
3
+ import { ImageProps } from '@asnewyla/image';
4
+
5
+ type CardPadding = 'sm' | 'md' | 'lg';
6
+ type CardRadius = 'sm' | 'md' | 'lg' | 'full';
7
+ type CardProps = ComponentPropsWithoutRef<'div'> & {
8
+ children: ReactNode;
9
+ image?: Omit<ImageProps, 'radius'>;
10
+ padding?: CardPadding;
11
+ radius?: CardRadius;
12
+ };
13
+ declare const Card: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
14
+ children: ReactNode;
15
+ image?: Omit<ImageProps, "radius">;
16
+ padding?: CardPadding;
17
+ radius?: CardRadius;
18
+ } & react.RefAttributes<HTMLDivElement>>;
19
+
20
+ export { Card, type CardPadding, type CardProps, type CardRadius };
package/dist/index.js ADDED
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ var image = require('@asnewyla/image');
4
+ var react = require('react');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+
7
+ // src/components/Card.tsx
8
+ function CardInner({
9
+ children,
10
+ image: image$1,
11
+ padding = "md",
12
+ radius,
13
+ className,
14
+ ...restProps
15
+ }, ref) {
16
+ return /* @__PURE__ */ jsxRuntime.jsxs(
17
+ "div",
18
+ {
19
+ ref,
20
+ ...restProps,
21
+ className: ["xd-card", className].filter(Boolean).join(" "),
22
+ "data-padding": padding,
23
+ "data-radius": radius,
24
+ children: [
25
+ image$1 && /* @__PURE__ */ jsxRuntime.jsx(image.Image, { ...image$1 }),
26
+ children
27
+ ]
28
+ }
29
+ );
30
+ }
31
+ var Card = react.forwardRef(CardInner);
32
+
33
+ exports.Card = Card;
34
+ //# sourceMappingURL=index.js.map
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/Card.tsx"],"names":["image","jsxs","jsx","Image","forwardRef"],"mappings":";;;;;;;AAmBA,SAAS,SAAA,CACP;AAAA,EACE,QAAA;AAAA,SACAA,OAAA;AAAA,EACA,OAAA,GAAU,IAAA;AAAA,EACV,MAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAG;AACL,CAAA,EACA,GAAA,EACA;AACA,EAAA,uBACEC,eAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,GAAA;AAAA,MACC,GAAG,SAAA;AAAA,MACJ,SAAA,EAAW,CAAC,SAAA,EAAW,SAAS,EAAE,MAAA,CAAO,OAAO,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA;AAAA,MAC1D,cAAA,EAAc,OAAA;AAAA,MACd,aAAA,EAAa,MAAA;AAAA,MAEZ,QAAA,EAAA;AAAA,QAAAD,OAAA,oBAASE,cAAA,CAACC,WAAA,EAAA,EAAO,GAAGH,OAAA,EAAO,CAAA;AAAA,QAC3B;AAAA;AAAA;AAAA,GACH;AAEJ;AAEO,IAAM,IAAA,GAAOI,iBAAsC,SAAS","file":"index.js","sourcesContent":["import { Image, type ImageProps } from '@asnewyla/image';\r\nimport {\r\n type ComponentPropsWithoutRef,\r\n type ForwardedRef,\r\n type ReactNode,\r\n forwardRef,\r\n} from 'react';\r\nimport './Card.css';\r\n\r\nexport type CardPadding = 'sm' | 'md' | 'lg';\r\nexport type CardRadius = 'sm' | 'md' | 'lg' | 'full';\r\n\r\nexport type CardProps = ComponentPropsWithoutRef<'div'> & {\r\n children: ReactNode;\r\n image?: Omit<ImageProps, 'radius'>;\r\n padding?: CardPadding;\r\n radius?: CardRadius;\r\n};\r\n\r\nfunction CardInner(\r\n {\r\n children,\r\n image,\r\n padding = 'md',\r\n radius,\r\n className,\r\n ...restProps\r\n }: CardProps,\r\n ref: ForwardedRef<HTMLDivElement>,\r\n) {\r\n return (\r\n <div\r\n ref={ref}\r\n {...restProps}\r\n className={['xd-card', className].filter(Boolean).join(' ')}\r\n data-padding={padding}\r\n data-radius={radius}\r\n >\r\n {image && <Image {...image} />}\r\n {children}\r\n </div>\r\n );\r\n}\r\n\r\nexport const Card = forwardRef<HTMLDivElement, CardProps>(CardInner);\r\n"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,33 @@
1
+ import { Image } from '@asnewyla/image';
2
+ import { forwardRef } from 'react';
3
+ import { jsxs, jsx } from 'react/jsx-runtime';
4
+
5
+ // src/components/Card.tsx
6
+ function CardInner({
7
+ children,
8
+ image,
9
+ padding = "md",
10
+ radius,
11
+ className,
12
+ ...restProps
13
+ }, ref) {
14
+ return /* @__PURE__ */ jsxs(
15
+ "div",
16
+ {
17
+ ref,
18
+ ...restProps,
19
+ className: ["xd-card", className].filter(Boolean).join(" "),
20
+ "data-padding": padding,
21
+ "data-radius": radius,
22
+ children: [
23
+ image && /* @__PURE__ */ jsx(Image, { ...image }),
24
+ children
25
+ ]
26
+ }
27
+ );
28
+ }
29
+ var Card = forwardRef(CardInner);
30
+
31
+ export { Card };
32
+ //# sourceMappingURL=index.mjs.map
33
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/Card.tsx"],"names":[],"mappings":";;;;;AAmBA,SAAS,SAAA,CACP;AAAA,EACE,QAAA;AAAA,EACA,KAAA;AAAA,EACA,OAAA,GAAU,IAAA;AAAA,EACV,MAAA;AAAA,EACA,SAAA;AAAA,EACA,GAAG;AACL,CAAA,EACA,GAAA,EACA;AACA,EAAA,uBACE,IAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACC,GAAA;AAAA,MACC,GAAG,SAAA;AAAA,MACJ,SAAA,EAAW,CAAC,SAAA,EAAW,SAAS,EAAE,MAAA,CAAO,OAAO,CAAA,CAAE,IAAA,CAAK,GAAG,CAAA;AAAA,MAC1D,cAAA,EAAc,OAAA;AAAA,MACd,aAAA,EAAa,MAAA;AAAA,MAEZ,QAAA,EAAA;AAAA,QAAA,KAAA,oBAAS,GAAA,CAAC,KAAA,EAAA,EAAO,GAAG,KAAA,EAAO,CAAA;AAAA,QAC3B;AAAA;AAAA;AAAA,GACH;AAEJ;AAEO,IAAM,IAAA,GAAO,WAAsC,SAAS","file":"index.mjs","sourcesContent":["import { Image, type ImageProps } from '@asnewyla/image';\r\nimport {\r\n type ComponentPropsWithoutRef,\r\n type ForwardedRef,\r\n type ReactNode,\r\n forwardRef,\r\n} from 'react';\r\nimport './Card.css';\r\n\r\nexport type CardPadding = 'sm' | 'md' | 'lg';\r\nexport type CardRadius = 'sm' | 'md' | 'lg' | 'full';\r\n\r\nexport type CardProps = ComponentPropsWithoutRef<'div'> & {\r\n children: ReactNode;\r\n image?: Omit<ImageProps, 'radius'>;\r\n padding?: CardPadding;\r\n radius?: CardRadius;\r\n};\r\n\r\nfunction CardInner(\r\n {\r\n children,\r\n image,\r\n padding = 'md',\r\n radius,\r\n className,\r\n ...restProps\r\n }: CardProps,\r\n ref: ForwardedRef<HTMLDivElement>,\r\n) {\r\n return (\r\n <div\r\n ref={ref}\r\n {...restProps}\r\n className={['xd-card', className].filter(Boolean).join(' ')}\r\n data-padding={padding}\r\n data-radius={radius}\r\n >\r\n {image && <Image {...image} />}\r\n {children}\r\n </div>\r\n );\r\n}\r\n\r\nexport const Card = forwardRef<HTMLDivElement, CardProps>(CardInner);\r\n"]}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@asnewyla/card",
3
+ "version": "0.2.0",
4
+ "description": "Content card surface with an optional image, padding, and radius",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/xavierDelaFuente/xd-components.git",
9
+ "directory": "packages/card"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "main": "dist/index.js",
15
+ "module": "dist/index.mjs",
16
+ "types": "dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.mjs",
20
+ "require": "./dist/index.js",
21
+ "types": "./dist/index.d.ts"
22
+ },
23
+ "./styles.css": "./dist/index.css"
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "sideEffects": [
29
+ "*.css"
30
+ ],
31
+ "keywords": [
32
+ "react",
33
+ "card",
34
+ "surface",
35
+ "accessible"
36
+ ],
37
+ "peerDependencies": {
38
+ "react": "^18.0.0 || ^19.0.0",
39
+ "react-dom": "^18.0.0 || ^19.0.0"
40
+ },
41
+ "dependencies": {
42
+ "@asnewyla/image": "0.2.0"
43
+ },
44
+ "devDependencies": {
45
+ "@testing-library/jest-dom": "^6.4.0",
46
+ "@testing-library/react": "^16.0.0",
47
+ "@testing-library/user-event": "^14.5.0",
48
+ "@vitest/coverage-v8": "^2.0.0",
49
+ "jsdom": "^24.0.0",
50
+ "react": "^18.3.0",
51
+ "react-dom": "^18.3.0",
52
+ "tsup": "^8.1.0",
53
+ "typescript": "^5.5.0",
54
+ "vitest": "^2.0.0"
55
+ },
56
+ "scripts": {
57
+ "build": "tsup",
58
+ "test": "vitest run",
59
+ "test:watch": "vitest",
60
+ "test:coverage": "vitest run --coverage",
61
+ "type-check": "tsc --noEmit"
62
+ }
63
+ }