@pindoba/astro-textarea 0.0.0-alpha-20260829223243

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,12 @@
1
+ Copyright 2025 Eduardo Lopes
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
8
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
9
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
10
+ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
11
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
12
+ DEALINGS IN THE SOFTWARE.
package/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ // Do not write code directly here, instead use the `src` folder!
2
+ // Then, use this file to export everything you want your user to access.
3
+
4
+ import Textarea from "./src/Textarea.astro";
5
+ import TextareaRoot from "./src/TextareaRoot.astro";
6
+ import TextareaField from "./src/TextareaField.astro";
7
+
8
+ export * from "./src/Textarea.astro";
9
+ export * from "./src/TextareaRoot.astro";
10
+ export * from "./src/TextareaField.astro";
11
+ export { TextareaRoot, TextareaField };
12
+ export default Textarea;
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@pindoba/astro-textarea",
3
+ "version": "0.0.0-alpha-20260829223243",
4
+ "homepage": "https://github.com/EduardoLopes/pindoba/tree/main/packages/ui/astro/textarea#README.md",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/EduardoLopes/pindoba.git",
8
+ "directory": "packages/ui/astro/textarea"
9
+ },
10
+ "sideEffects": false,
11
+ "license": "MIT",
12
+ "type": "module",
13
+ "exports": {
14
+ ".": "./index.ts",
15
+ "./demos": "./src/demos/index.ts",
16
+ "./demos/feedback": "./src/demos/feedback.astro",
17
+ "./demos/size": "./src/demos/size.astro",
18
+ "./demos/leading-trailing-sizes": "./src/demos/leading-trailing-sizes.astro",
19
+ "./demos/auto-resize": "./src/demos/auto-resize.astro",
20
+ "./demos/character-count": "./src/demos/character-count.astro",
21
+ "./demos/custom": "./src/demos/custom.astro"
22
+ },
23
+ "files": [
24
+ "src",
25
+ "index.ts"
26
+ ],
27
+ "keywords": [
28
+ "astro-component"
29
+ ],
30
+ "devDependencies": {
31
+ "@astrojs/check": "^0.9.10",
32
+ "@pindoba/astro-affix": "0.0.0-alpha-20260829223243",
33
+ "@pindoba/astro-attachment": "0.0.0-alpha-20260829223243",
34
+ "@pindoba/astro-badge": "0.0.0-alpha-20260829223243",
35
+ "@pindoba/astro-stamp": "0.0.0-alpha-20260829223243",
36
+ "astro": "^7.2.9",
37
+ "typescript": "^7.0.2"
38
+ },
39
+ "peerDependencies": {
40
+ "astro": "^4.0.0"
41
+ },
42
+ "dependencies": {
43
+ "@lucide/astro": "^1.35.0",
44
+ "@pindoba/core-textarea": "0.0.0-alpha-20260829223243",
45
+ "@pindoba/styled-system": "0.0.0-alpha-20260829223243"
46
+ },
47
+ "scripts": {
48
+ "lint": "TIMING=1 eslint . --max-warnings 0",
49
+ "lint:fix": "TIMING=1 eslint . --fix --max-warnings 0",
50
+ "link": "pnpm link",
51
+ "unlink": "pnpm unlink",
52
+ "check": "astro check",
53
+ "dev": "astro check --watch",
54
+ "clean": "rm -rf .astro && rm -rf node_modules && rm -rf .turbo",
55
+ "format": "prettier --check . --ignore-path \"$PRETTIER_IGNORE_PATH\"",
56
+ "format:fix": "prettier --write . --ignore-path \"$PRETTIER_IGNORE_PATH\""
57
+ }
58
+ }
@@ -0,0 +1,143 @@
1
+ ---
2
+ import {
3
+ connectTextarea,
4
+ type TextareaBaseProps,
5
+ } from "@pindoba/core-textarea";
6
+ import type { HTMLAttributes } from "astro/types";
7
+
8
+ type TextareaElementHTMLAttributes = HTMLAttributes<"textarea">;
9
+
10
+ // `rows` is redeclared on `TextareaBaseProps` (typed `number`), so omit the
11
+ // native attribute to avoid an incompatible-extends clash.
12
+ type DefaultTextareaProps = Omit<
13
+ HTMLAttributes<"textarea">,
14
+ "size" | "background" | "rows"
15
+ >;
16
+
17
+ export interface TextareaProps
18
+ extends DefaultTextareaProps, TextareaBaseProps {}
19
+
20
+ const {
21
+ feedback,
22
+ size,
23
+ background,
24
+ border,
25
+ fullWidth,
26
+ passThrough,
27
+ class: className,
28
+ rows,
29
+ resize,
30
+ autoResize,
31
+ value,
32
+ ...rest
33
+ }: TextareaProps = Astro.props;
34
+
35
+ const api = connectTextarea({
36
+ // Claim marker for this file's boot script. `data-textarea-root` is baked by
37
+ // the CORE connect, so a React/Svelte/Vue root carries it too — a
38
+ // document-wide query would adopt their instances on any page that mixes
39
+ // frameworks. Only Astro-rendered roots carry this one.
40
+ "data-astro-textarea": "",
41
+ feedback,
42
+ size,
43
+ background,
44
+ border,
45
+ fullWidth,
46
+ passThrough,
47
+ rows,
48
+ resize,
49
+ autoResize,
50
+ class: className,
51
+ textareaAttrs: rest,
52
+ });
53
+ ---
54
+
55
+ {
56
+ /* Declarative sugar: `leading`/`trailing` slots render an affix box (the
57
+ `[data-affix]` span the Control Var Contract aligns) around the field — no
58
+ `<Affix>` import needed. Customize the box via `passThrough.leading` (e.g.
59
+ `{ props: { decorative: true } }`). For multiple addons / custom layout,
60
+ compose the parts: `<TextareaRoot>` + `<Affix>` + `<TextareaField>`. */
61
+ }
62
+ <div {...api.rootProps}>
63
+ {
64
+ Astro.slots.has("leading") && (
65
+ <span {...api.leadingAffixProps}>
66
+ {/* Leading addon content (icon/badge), rendered inside an affix box the Control Var Contract aligns. Pass a `<Stamp emphasis="ghost">` for icons; style the box via `passThrough.leading`. @group Slots */}
67
+ <slot name="leading" />
68
+ </span>
69
+ )
70
+ }
71
+ <textarea {...api.textareaProps as TextareaElementHTMLAttributes}
72
+ >{value}</textarea
73
+ >
74
+ {
75
+ Astro.slots.has("trailing") && (
76
+ <span {...api.trailingAffixProps}>
77
+ {/* Trailing addon content, rendered inside an end-pinned affix box. @group Slots */}
78
+ <slot name="trailing" />
79
+ </span>
80
+ )
81
+ }
82
+ </div>
83
+
84
+ <script>
85
+ // Keep the interactive-affix selector in sync with `connect-textarea.ts`
86
+ // (`TEXTAREA_INTERACTIVE_AFFIX_SELECTOR`). Clicking dead chrome / a decorative
87
+ // affix focuses the field; clicking an interactive addon is left alone.
88
+ const INTERACTIVE =
89
+ "button:not([tabindex='-1']), a[href]:not([tabindex='-1']), input, select, textarea, [role='button']:not([tabindex='-1']), [tabindex]:not([tabindex='-1'])";
90
+ function boot() {
91
+ document
92
+ .querySelectorAll<HTMLElement>("[data-astro-textarea]")
93
+ .forEach((root) => {
94
+ // Only wire Astro-rendered instances. React/Svelte/Vue islands emit the
95
+ // same `data-textarea-root` (baked by the core) but get click-to-focus
96
+ // from the core `onclick` and hydrate their own DOM — mutating them here
97
+ // would race hydration and throw a mismatch. Astro's own demos render as
98
+ // static server HTML (no `<astro-island>` wrapper).
99
+ if (root.closest("astro-island")) return;
100
+ // Guard against double-wiring when Textarea and TextareaRoot share a
101
+ // page — both ship this script keyed on the same selector.
102
+ if (root.dataset.textareaRootWired) return;
103
+ root.dataset.textareaRootWired = "true";
104
+ root.addEventListener("click", (e) => {
105
+ const textarea = root.querySelector("textarea");
106
+ if (!textarea) return;
107
+ const target = e.target;
108
+ if (target === textarea) return;
109
+ if (target instanceof Element && target.closest(INTERACTIVE)) return;
110
+ textarea.focus();
111
+ });
112
+ });
113
+ }
114
+
115
+ boot();
116
+ document.addEventListener("astro:page-load", boot);
117
+ </script>
118
+
119
+ <script>
120
+ // Auto-grow textareas flagged with `data-auto-resize` (set by the connect
121
+ // when `autoResize` is truthy). Size to fit content on mount and on input.
122
+ function boot() {
123
+ document
124
+ .querySelectorAll<HTMLTextAreaElement>("textarea[data-auto-resize]")
125
+ .forEach((el) => {
126
+ // Skip hydrated islands (React/Svelte/Vue self-wire auto-resize); only
127
+ // grow Astro's own static textareas so we don't mutate island DOM
128
+ // pre-hydration.
129
+ if (el.closest("astro-island")) return;
130
+ if (el.dataset.autoResizeWired) return;
131
+ el.dataset.autoResizeWired = "true";
132
+ const fit = () => {
133
+ el.style.height = "auto";
134
+ el.style.height = el.scrollHeight + "px";
135
+ };
136
+ fit();
137
+ el.addEventListener("input", fit);
138
+ });
139
+ }
140
+
141
+ boot();
142
+ document.addEventListener("astro:page-load", boot);
143
+ </script>
@@ -0,0 +1,63 @@
1
+ ---
2
+ import {
3
+ connectTextareaField,
4
+ type TextareaFieldBaseProps,
5
+ } from "@pindoba/core-textarea";
6
+ import type { HTMLAttributes } from "astro/types";
7
+
8
+ type TextareaElementHTMLAttributes = HTMLAttributes<"textarea">;
9
+
10
+ export interface TextareaFieldProps
11
+ extends
12
+ Omit<HTMLAttributes<"textarea">, "rows">,
13
+ TextareaFieldBaseProps<HTMLAttributes<"textarea">> {}
14
+
15
+ const {
16
+ class: className,
17
+ passThrough,
18
+ rows,
19
+ resize,
20
+ autoResize,
21
+ value,
22
+ ...rest
23
+ }: TextareaFieldProps = Astro.props;
24
+
25
+ const api = connectTextareaField({
26
+ passThrough,
27
+ rows,
28
+ resize,
29
+ autoResize,
30
+ class: className,
31
+ textareaAttrs: rest,
32
+ });
33
+ ---
34
+
35
+ {
36
+ /* The bare field part — render inside a <TextareaRoot>, which owns the
37
+ chrome, the row sizing (data-control-size), and click-to-focus. */
38
+ }
39
+ <textarea {...api.rootProps as TextareaElementHTMLAttributes}>{value}</textarea>
40
+
41
+ <script>
42
+ // Auto-grow textareas flagged with `data-auto-resize` (set by the connect
43
+ // when `autoResize` is truthy). Size to fit content on mount and on input.
44
+ function boot() {
45
+ document
46
+ .querySelectorAll<HTMLTextAreaElement>("textarea[data-auto-resize]")
47
+ .forEach((el) => {
48
+ // Skip hydrated islands (React/Svelte/Vue self-wire auto-resize).
49
+ if (el.closest("astro-island")) return;
50
+ if (el.dataset.autoResizeWired) return;
51
+ el.dataset.autoResizeWired = "true";
52
+ const fit = () => {
53
+ el.style.height = "auto";
54
+ el.style.height = el.scrollHeight + "px";
55
+ };
56
+ fit();
57
+ el.addEventListener("input", fit);
58
+ });
59
+ }
60
+
61
+ boot();
62
+ document.addEventListener("astro:page-load", boot);
63
+ </script>
@@ -0,0 +1,62 @@
1
+ ---
2
+ import {
3
+ connectTextareaRoot,
4
+ type TextareaRootBaseProps,
5
+ } from "@pindoba/core-textarea";
6
+ import type { HTMLAttributes } from "astro/types";
7
+
8
+ export type TextareaRootProps = HTMLAttributes<"div"> &
9
+ TextareaRootBaseProps<HTMLAttributes<"div">>;
10
+
11
+ const { class: className, ...rest }: TextareaRootProps = Astro.props;
12
+
13
+ const api = connectTextareaRoot({
14
+ // Claim marker for this file's boot script. `data-textarea-root` is baked by
15
+ // the CORE connect, so a React/Svelte/Vue root carries it too — a
16
+ // document-wide query would adopt their instances on any page that mixes
17
+ // frameworks. Only Astro-rendered roots carry this one.
18
+ "data-astro-textarea": "",
19
+ ...rest,
20
+ class: className,
21
+ });
22
+ ---
23
+
24
+ {
25
+ /* The chrome-carrying frame of the textarea family. Compose `<Affix>` boxes
26
+ and a `<TextareaField>` in the default slot — the Control Var Contract
27
+ aligns them and a click anywhere in the frame focuses the field (script
28
+ below). */
29
+ }
30
+ <div {...api.rootProps}>
31
+ <slot />
32
+ </div>
33
+
34
+ <script>
35
+ // Keep the interactive-affix selector in sync with `connect-textarea.ts`
36
+ // (`TEXTAREA_INTERACTIVE_AFFIX_SELECTOR`). Clicking dead chrome / a decorative
37
+ // affix focuses the field; clicking an interactive addon is left alone.
38
+ const INTERACTIVE =
39
+ "button:not([tabindex='-1']), a[href]:not([tabindex='-1']), input, select, textarea, [role='button']:not([tabindex='-1']), [tabindex]:not([tabindex='-1'])";
40
+ function boot() {
41
+ document
42
+ .querySelectorAll<HTMLElement>("[data-astro-textarea]")
43
+ .forEach((root) => {
44
+ // Only wire Astro-rendered instances — hydrated islands
45
+ // (`<astro-island>`) get click-to-focus from the core `onclick`.
46
+ if (root.closest("astro-island")) return;
47
+ if (root.dataset.textareaRootWired) return;
48
+ root.dataset.textareaRootWired = "true";
49
+ root.addEventListener("click", (e) => {
50
+ const textarea = root.querySelector("textarea");
51
+ if (!textarea) return;
52
+ const target = e.target;
53
+ if (target === textarea) return;
54
+ if (target instanceof Element && target.closest(INTERACTIVE)) return;
55
+ textarea.focus();
56
+ });
57
+ });
58
+ }
59
+
60
+ boot();
61
+ document.addEventListener("astro:page-load", boot);
62
+ </script>
@@ -0,0 +1,14 @@
1
+ ---
2
+ import Textarea from "../Textarea.astro";
3
+ import { stack } from "@pindoba/styled-system/patterns";
4
+ ---
5
+
6
+ <div class={stack({ gap: "md", direction: "column" })}>
7
+ <Textarea
8
+ autoResize
9
+ resize="none"
10
+ rows={2}
11
+ placeholder="Type multiple lines…"
12
+ fullWidth
13
+ />
14
+ </div>
@@ -0,0 +1,29 @@
1
+ ---
2
+ import Textarea from "../Textarea.astro";
3
+ import Attachment from "@pindoba/astro-attachment";
4
+ import { css } from "@pindoba/styled-system/css";
5
+
6
+ // The counter floats below the field via the Attachment component. Astro
7
+ // renders statically, so the count is illustrative — the Svelte / React / Vue
8
+ // tabs update it live.
9
+ const MAX = 280;
10
+
11
+ const field = {
12
+ root: { style: { display: "block", width: "20rem", maxWidth: "100%" } },
13
+ };
14
+
15
+ const counter = css({
16
+ fontSize: "xs",
17
+ fontVariantNumeric: "tabular-nums",
18
+ color: "neutral.text.muted",
19
+ background: "neutral.surface.hill",
20
+ borderRadius: "sm",
21
+ paddingInline: "2xs",
22
+ paddingBlock: "3xs",
23
+ });
24
+ ---
25
+
26
+ <Attachment placement="bottom-end" anchor="outside" passThrough={field}>
27
+ <Textarea rows={4} fullWidth maxlength={MAX} placeholder="Write a message…" />
28
+ <span slot="content" class={counter}>0 / {MAX}</span>
29
+ </Attachment>
@@ -0,0 +1,32 @@
1
+ ---
2
+ import Textarea from "../Textarea.astro";
3
+ import { stack } from "@pindoba/styled-system/patterns";
4
+ ---
5
+
6
+ <div class={stack({ gap: "xl", direction: "column" })}>
7
+ <div>
8
+ <h3>Custom style via passThrough</h3>
9
+ <Textarea
10
+ placeholder="Custom root style"
11
+ passThrough={{
12
+ root: { style: { borderRadius: "full" } },
13
+ textarea: { style: { fontStyle: "italic" } },
14
+ }}
15
+ />
16
+ </div>
17
+
18
+ <div>
19
+ <h3>Custom props via passThrough</h3>
20
+ <Textarea
21
+ placeholder="Message..."
22
+ passThrough={{
23
+ textarea: {
24
+ props: {
25
+ "aria-label": "Message textarea",
26
+ "data-testid": "message-textarea",
27
+ },
28
+ },
29
+ }}
30
+ />
31
+ </div>
32
+ </div>
@@ -0,0 +1,12 @@
1
+ ---
2
+ import Textarea from "../Textarea.astro";
3
+ import { stack } from "@pindoba/styled-system/patterns";
4
+ ---
5
+
6
+ <div class={stack({ gap: "md", direction: "column" })}>
7
+ <Textarea feedback="neutral" placeholder="Neutral" />
8
+ <Textarea feedback="primary" placeholder="Primary" />
9
+ <Textarea feedback="success" placeholder="Success" />
10
+ <Textarea feedback="danger" placeholder="Danger" />
11
+ <Textarea feedback="warning" placeholder="Warning" />
12
+ </div>
@@ -0,0 +1,6 @@
1
+ export { default as Feedback } from "./feedback.astro";
2
+ export { default as Size } from "./size.astro";
3
+ export { default as LeadingTrailingSizes } from "./leading-trailing-sizes.astro";
4
+ export { default as AutoResize } from "./auto-resize.astro";
5
+ export { default as CharacterCount } from "./character-count.astro";
6
+ export { default as Custom } from "./custom.astro";
@@ -0,0 +1,42 @@
1
+ ---
2
+ import TextareaRoot from "../TextareaRoot.astro";
3
+ import TextareaField from "../TextareaField.astro";
4
+ import Affix from "@pindoba/astro-affix";
5
+ import Stamp from "@pindoba/astro-stamp";
6
+ import { MessageSquare, Search, Paperclip } from "@lucide/astro";
7
+ import { stack } from "@pindoba/styled-system/patterns";
8
+
9
+ const sizes = ["xs", "sm", "md", "lg"] as const;
10
+ ---
11
+
12
+ <div class={stack({ gap: "md", direction: "column" })}>
13
+ {
14
+ sizes.map((size) => (
15
+ <TextareaRoot size={size}>
16
+ <Affix>
17
+ <Stamp emphasis="ghost" border="muted">
18
+ <MessageSquare />
19
+ </Stamp>
20
+ </Affix>
21
+ <TextareaField placeholder={`Message (${size})`} />
22
+ <Affix side="end">
23
+ <Stamp emphasis="ghost" border="muted">
24
+ <Paperclip />
25
+ </Stamp>
26
+ </Affix>
27
+ </TextareaRoot>
28
+ ))
29
+ }
30
+ {
31
+ sizes.map((size) => (
32
+ <TextareaRoot size={size}>
33
+ <Affix>
34
+ <Stamp emphasis="ghost" border="muted">
35
+ <Search />
36
+ </Stamp>
37
+ </Affix>
38
+ <TextareaField placeholder={`Search (${size})`} />
39
+ </TextareaRoot>
40
+ ))
41
+ }
42
+ </div>
@@ -0,0 +1,11 @@
1
+ ---
2
+ import Textarea from "../Textarea.astro";
3
+ import { stack } from "@pindoba/styled-system/patterns";
4
+ ---
5
+
6
+ <div class={stack({ gap: "md", direction: "column" })}>
7
+ <Textarea size="xs" placeholder="Extra Small" />
8
+ <Textarea size="sm" placeholder="Small" />
9
+ <Textarea size="md" placeholder="Medium" />
10
+ <Textarea size="lg" placeholder="Large" />
11
+ </div>
package/src/env.d.ts ADDED
@@ -0,0 +1 @@
1
+ /// <reference types="astro/client" />