@mrcaktuz/sds-react 0.0.0-stage → 0.1.1
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 +438 -2
- package/dist/grid.cjs +15694 -0
- package/dist/grid.d.cts +43 -0
- package/dist/grid.d.ts +43 -0
- package/dist/grid.js +15648 -0
- package/dist/index.cjs +259 -0
- package/dist/index.d.cts +52 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +232 -0
- package/package.json +48 -3
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
SDSButton: () => SDSButton,
|
|
24
|
+
SDSInput: () => SDSInput,
|
|
25
|
+
SDSPagination: () => SDSPagination,
|
|
26
|
+
getPageItems: () => getPageItems
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/components/button/button.tsx
|
|
31
|
+
var import_sds_tokens = require("@mrcaktuz/sds-tokens");
|
|
32
|
+
var import_theme = require("@mrcaktuz/sds-styles/theme.css");
|
|
33
|
+
var import_button = require("@mrcaktuz/sds-styles/components/button.css");
|
|
34
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
+
function SDSButton({
|
|
36
|
+
variant = import_sds_tokens.defaultButtonVariant,
|
|
37
|
+
color = import_sds_tokens.defaultButtonColor,
|
|
38
|
+
small = false,
|
|
39
|
+
icon,
|
|
40
|
+
iconPosition = "left",
|
|
41
|
+
iconOnly = false,
|
|
42
|
+
type = "button",
|
|
43
|
+
className,
|
|
44
|
+
children,
|
|
45
|
+
...props
|
|
46
|
+
}) {
|
|
47
|
+
const classes = [
|
|
48
|
+
"sds-btn",
|
|
49
|
+
`sds-btn--${variant}--${color}`,
|
|
50
|
+
small && "sds-btn--small",
|
|
51
|
+
iconOnly && "sds-btn--iconOnly",
|
|
52
|
+
icon && `sds-btn__icon--${iconPosition}`,
|
|
53
|
+
className
|
|
54
|
+
].filter(Boolean).join(" ");
|
|
55
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", { type, className: classes, ...props, children: [
|
|
56
|
+
icon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "sds-icon", "aria-hidden": "true", children: icon }),
|
|
57
|
+
children && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "sds-btn__text", children })
|
|
58
|
+
] });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/components/input/input.tsx
|
|
62
|
+
var import_react = require("react");
|
|
63
|
+
var import_input = require("@mrcaktuz/sds-styles/components/input.css");
|
|
64
|
+
var import_theme2 = require("@mrcaktuz/sds-styles/theme.css");
|
|
65
|
+
|
|
66
|
+
// src/components/input/input-icons.tsx
|
|
67
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
68
|
+
var CircleAlertIcon = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { className: "sds-input__icon", viewBox: "0 0 16 16", "aria-hidden": "true", children: [
|
|
69
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M14.1663 8C14.1663 4.59435 11.4059 1.83318 8.00024 1.83301C4.59449 1.83301 1.83325 4.59424 1.83325 8C1.83343 11.4056 4.5946 14.166 8.00024 14.166C11.4057 14.1658 14.1661 11.4055 14.1663 8ZM15.1663 8C15.1661 11.9578 11.958 15.1658 8.00024 15.166C4.04231 15.166 0.833428 11.9579 0.833252 8C0.833252 4.04196 4.0422 0.833008 8.00024 0.833008C11.9581 0.833184 15.1663 4.04207 15.1663 8Z" }),
|
|
70
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M7.5 8V5.33301C7.5 5.05687 7.72386 4.83301 8 4.83301C8.27614 4.83301 8.5 5.05687 8.5 5.33301V8C8.49982 8.27599 8.27603 8.5 8 8.5C7.72397 8.5 7.50018 8.27599 7.5 8Z" }),
|
|
71
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M8.00684 10.167C8.2829 10.1671 8.50684 10.3909 8.50684 10.667C8.50684 10.9431 8.2829 11.1669 8.00684 11.167H8C7.72386 11.167 7.5 10.9431 7.5 10.667C7.5 10.3908 7.72386 10.167 8 10.167H8.00684Z" })
|
|
72
|
+
] });
|
|
73
|
+
var CheckmarkOutlineIcon = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { className: "sds-input__icon", viewBox: "0 0 16 16", "aria-hidden": "true", children: [
|
|
74
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M7 10.707L4.5 8.2065L5.2065 7.5L7 9.293L10.7925 5.5L11.5 6.2075L7 10.707Z" }),
|
|
75
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M8 1C6.61553 1 5.26216 1.41054 4.11101 2.17971C2.95987 2.94888 2.06266 4.04213 1.53285 5.32122C1.00303 6.6003 0.86441 8.00776 1.13451 9.36563C1.4046 10.7235 2.07129 11.9708 3.05026 12.9497C4.02922 13.9287 5.2765 14.5954 6.63437 14.8655C7.99224 15.1356 9.3997 14.997 10.6788 14.4672C11.9579 13.9373 13.0511 13.0401 13.8203 11.889C14.5895 10.7378 15 9.38447 15 8C15 6.14348 14.2625 4.36301 12.9497 3.05025C11.637 1.7375 9.85652 1 8 1ZM8 14C6.81332 14 5.65328 13.6481 4.66658 12.9888C3.67989 12.3295 2.91085 11.3925 2.45673 10.2961C2.0026 9.19974 1.88378 7.99334 2.11529 6.82946C2.3468 5.66557 2.91825 4.59647 3.75736 3.75736C4.59648 2.91824 5.66558 2.3468 6.82946 2.11529C7.99335 1.88378 9.19975 2.0026 10.2961 2.45672C11.3925 2.91085 12.3295 3.67988 12.9888 4.66658C13.6481 5.65327 14 6.81331 14 8C14 9.5913 13.3679 11.1174 12.2426 12.2426C11.1174 13.3679 9.5913 14 8 14Z" })
|
|
76
|
+
] });
|
|
77
|
+
|
|
78
|
+
// src/components/input/input.tsx
|
|
79
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
80
|
+
function SDSInput({
|
|
81
|
+
id,
|
|
82
|
+
type = "text",
|
|
83
|
+
label,
|
|
84
|
+
placeholder,
|
|
85
|
+
value,
|
|
86
|
+
status = "default",
|
|
87
|
+
message,
|
|
88
|
+
onChange,
|
|
89
|
+
onBlur
|
|
90
|
+
}) {
|
|
91
|
+
const generatedId = (0, import_react.useId)();
|
|
92
|
+
const inputId = id ?? generatedId;
|
|
93
|
+
const messageId = `${inputId}-message`;
|
|
94
|
+
const showMessage = status !== "default" && !!message;
|
|
95
|
+
const [currentValue, setCurrentValue] = (0, import_react.useState)(value ?? "");
|
|
96
|
+
(0, import_react.useEffect)(() => {
|
|
97
|
+
if (value !== void 0) setCurrentValue(value);
|
|
98
|
+
}, [value]);
|
|
99
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: `sds-input sds-input--${status}`, children: [
|
|
100
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { htmlFor: inputId, className: "sds-input__label", children: label }),
|
|
101
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "sds-input__container", children: [
|
|
102
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
103
|
+
"input",
|
|
104
|
+
{
|
|
105
|
+
id: inputId,
|
|
106
|
+
type,
|
|
107
|
+
placeholder,
|
|
108
|
+
value: currentValue,
|
|
109
|
+
"aria-invalid": status === "error" || void 0,
|
|
110
|
+
"aria-describedby": showMessage ? messageId : void 0,
|
|
111
|
+
onChange: (event) => {
|
|
112
|
+
setCurrentValue(event.target.value);
|
|
113
|
+
onChange?.(event.target.value, event);
|
|
114
|
+
},
|
|
115
|
+
onBlur: (event) => onBlur?.(event.target.value, event)
|
|
116
|
+
}
|
|
117
|
+
),
|
|
118
|
+
status === "error" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CircleAlertIcon, {}),
|
|
119
|
+
status === "success" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CheckmarkOutlineIcon, {})
|
|
120
|
+
] }),
|
|
121
|
+
showMessage && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { id: messageId, className: "sds-input__message", children: message })
|
|
122
|
+
] });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/components/pagination/pagination.tsx
|
|
126
|
+
var import_react2 = require("react");
|
|
127
|
+
var import_pagination = require("@mrcaktuz/sds-styles/components/pagination.css");
|
|
128
|
+
var import_theme3 = require("@mrcaktuz/sds-styles/theme.css");
|
|
129
|
+
|
|
130
|
+
// src/components/pagination/pagination-icons.tsx
|
|
131
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
132
|
+
var base = {
|
|
133
|
+
width: 16,
|
|
134
|
+
height: 16,
|
|
135
|
+
viewBox: "0 0 24 24",
|
|
136
|
+
fill: "none",
|
|
137
|
+
stroke: "currentColor",
|
|
138
|
+
strokeWidth: 2,
|
|
139
|
+
strokeLinecap: "round",
|
|
140
|
+
strokeLinejoin: "round",
|
|
141
|
+
"aria-hidden": true
|
|
142
|
+
};
|
|
143
|
+
var ChevronLeft = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { ...base, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "m15 18-6-6 6-6" }) });
|
|
144
|
+
var ChevronRight = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { ...base, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "m9 18 6-6-6-6" }) });
|
|
145
|
+
var FirstPage = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { ...base, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M6 6v12M17 18l-6-6 6-6" }) });
|
|
146
|
+
var LastPage = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { ...base, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: "M18 6v12M7 18l6-6-6-6" }) });
|
|
147
|
+
|
|
148
|
+
// src/components/pagination/pagination.tsx
|
|
149
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
150
|
+
function getPageItems(page, pageCount) {
|
|
151
|
+
if (pageCount <= 7) return Array.from({ length: pageCount }, (_, i) => i + 1);
|
|
152
|
+
if (page <= 4) return [1, 2, 3, 4, 5, "ellipsis", pageCount];
|
|
153
|
+
if (page >= pageCount - 3)
|
|
154
|
+
return [1, "ellipsis", ...Array.from({ length: 5 }, (_, i) => pageCount - 4 + i)];
|
|
155
|
+
return [1, "ellipsis", page - 1, page, page + 1, "ellipsis", pageCount];
|
|
156
|
+
}
|
|
157
|
+
function SDSPagination({
|
|
158
|
+
page,
|
|
159
|
+
pageSize,
|
|
160
|
+
totalItems,
|
|
161
|
+
onPageChange,
|
|
162
|
+
onPageSizeChange,
|
|
163
|
+
showRowsPerPage = true,
|
|
164
|
+
pageSizeOptions = [15, 30, 50],
|
|
165
|
+
resultsSummary = (from, to, total) => `${from}\u2013${to} sur ${total}`,
|
|
166
|
+
className
|
|
167
|
+
}) {
|
|
168
|
+
const selectId = (0, import_react2.useId)();
|
|
169
|
+
const pageCount = Math.max(1, Math.ceil(totalItems / pageSize));
|
|
170
|
+
const from = totalItems === 0 ? 0 : (page - 1) * pageSize + 1;
|
|
171
|
+
const to = Math.min(page * pageSize, totalItems);
|
|
172
|
+
const isFirst = page <= 1;
|
|
173
|
+
const isLast = page >= pageCount;
|
|
174
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: ["sds-pagination", className].filter(Boolean).join(" "), children: [
|
|
175
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "sds-pagination__summary", children: [
|
|
176
|
+
showRowsPerPage && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
177
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: selectId, className: "sds-pagination__label", children: "Lignes par page" }),
|
|
178
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
179
|
+
"select",
|
|
180
|
+
{
|
|
181
|
+
id: selectId,
|
|
182
|
+
className: "sds-pagination__select",
|
|
183
|
+
value: pageSize,
|
|
184
|
+
onChange: (e) => onPageSizeChange?.(Number(e.target.value)),
|
|
185
|
+
children: pageSizeOptions.map((size) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: size, children: size }, size))
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
] }),
|
|
189
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "sds-pagination__results", "aria-live": "polite", children: resultsSummary(from, to, totalItems) })
|
|
190
|
+
] }),
|
|
191
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("nav", { className: "sds-pagination__nav", "aria-label": "Pagination", children: [
|
|
192
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
193
|
+
"button",
|
|
194
|
+
{
|
|
195
|
+
type: "button",
|
|
196
|
+
className: "sds-pagination__btn",
|
|
197
|
+
"aria-label": "Premi\xE8re page",
|
|
198
|
+
disabled: isFirst,
|
|
199
|
+
onClick: () => onPageChange(1),
|
|
200
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FirstPage, {})
|
|
201
|
+
}
|
|
202
|
+
),
|
|
203
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
204
|
+
"button",
|
|
205
|
+
{
|
|
206
|
+
type: "button",
|
|
207
|
+
className: "sds-pagination__btn",
|
|
208
|
+
"aria-label": "Page pr\xE9c\xE9dente",
|
|
209
|
+
disabled: isFirst,
|
|
210
|
+
onClick: () => onPageChange(page - 1),
|
|
211
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChevronLeft, {})
|
|
212
|
+
}
|
|
213
|
+
),
|
|
214
|
+
getPageItems(page, pageCount).map(
|
|
215
|
+
(item, i) => item === "ellipsis" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "sds-pagination__ellipsis", "aria-hidden": "true", children: "\u2026" }, `e${i}`) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
216
|
+
"button",
|
|
217
|
+
{
|
|
218
|
+
type: "button",
|
|
219
|
+
className: "sds-pagination__btn sds-pagination__page",
|
|
220
|
+
"aria-label": `Page ${item}`,
|
|
221
|
+
"aria-current": item === page ? "page" : void 0,
|
|
222
|
+
onClick: () => onPageChange(item),
|
|
223
|
+
children: item
|
|
224
|
+
},
|
|
225
|
+
item
|
|
226
|
+
)
|
|
227
|
+
),
|
|
228
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
229
|
+
"button",
|
|
230
|
+
{
|
|
231
|
+
type: "button",
|
|
232
|
+
className: "sds-pagination__btn",
|
|
233
|
+
"aria-label": "Page suivante",
|
|
234
|
+
disabled: isLast,
|
|
235
|
+
onClick: () => onPageChange(page + 1),
|
|
236
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ChevronRight, {})
|
|
237
|
+
}
|
|
238
|
+
),
|
|
239
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
240
|
+
"button",
|
|
241
|
+
{
|
|
242
|
+
type: "button",
|
|
243
|
+
className: "sds-pagination__btn",
|
|
244
|
+
"aria-label": "Derni\xE8re page",
|
|
245
|
+
disabled: isLast,
|
|
246
|
+
onClick: () => onPageChange(pageCount),
|
|
247
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(LastPage, {})
|
|
248
|
+
}
|
|
249
|
+
)
|
|
250
|
+
] })
|
|
251
|
+
] });
|
|
252
|
+
}
|
|
253
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
254
|
+
0 && (module.exports = {
|
|
255
|
+
SDSButton,
|
|
256
|
+
SDSInput,
|
|
257
|
+
SDSPagination,
|
|
258
|
+
getPageItems
|
|
259
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ButtonHTMLAttributes, ReactNode, ChangeEvent, FocusEvent } from 'react';
|
|
3
|
+
import { ButtonAppearance } from '@mrcaktuz/sds-tokens';
|
|
4
|
+
|
|
5
|
+
type SDSButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'color'> & ButtonAppearance & {
|
|
6
|
+
small?: boolean;
|
|
7
|
+
icon?: ReactNode;
|
|
8
|
+
iconPosition?: 'left' | 'right';
|
|
9
|
+
/** Hides the text — set `aria-label` */
|
|
10
|
+
iconOnly?: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare function SDSButton({ variant, color, small, icon, iconPosition, iconOnly, type, className, children, ...props }: SDSButtonProps): React.JSX.Element;
|
|
13
|
+
|
|
14
|
+
type SDSInputType = 'text' | 'email' | 'password' | 'number' | 'tel' | 'url' | 'search' | 'date';
|
|
15
|
+
/** "success" does not exist in the legacy DS: same rendering as "error", with the success color */
|
|
16
|
+
type SDSInputStatus = 'default' | 'error' | 'success';
|
|
17
|
+
type SDSInputProps = {
|
|
18
|
+
/** HTML id of the input, also links the label. Generated when missing */
|
|
19
|
+
id?: string;
|
|
20
|
+
type?: SDSInputType;
|
|
21
|
+
label?: string;
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
/** Fills the field and updates it when it changes */
|
|
24
|
+
value?: string;
|
|
25
|
+
status?: SDSInputStatus;
|
|
26
|
+
/** Shown under the field for the "error" and "success" statuses */
|
|
27
|
+
message?: string;
|
|
28
|
+
/** Called on each keystroke, with the new value */
|
|
29
|
+
onChange?: (value: string, event: ChangeEvent<HTMLInputElement>) => void;
|
|
30
|
+
/** Called when the field loses focus, with the current value */
|
|
31
|
+
onBlur?: (value: string, event: FocusEvent<HTMLInputElement>) => void;
|
|
32
|
+
};
|
|
33
|
+
declare function SDSInput({ id, type, label, placeholder, value, status, message, onChange, onBlur, }: SDSInputProps): React.JSX.Element;
|
|
34
|
+
|
|
35
|
+
type SDSPaginationProps = {
|
|
36
|
+
/** Current page, starting at 1 */
|
|
37
|
+
page: number;
|
|
38
|
+
pageSize: number;
|
|
39
|
+
totalItems: number;
|
|
40
|
+
onPageChange: (page: number) => void;
|
|
41
|
+
onPageSizeChange?: (pageSize: number) => void;
|
|
42
|
+
/** Figma "Show rows per page" */
|
|
43
|
+
showRowsPerPage?: boolean;
|
|
44
|
+
pageSizeOptions?: number[];
|
|
45
|
+
/** Figma "Results summary": replaces the default "1–15 sur 100" */
|
|
46
|
+
resultsSummary?: (from: number, to: number, total: number) => string;
|
|
47
|
+
className?: string;
|
|
48
|
+
};
|
|
49
|
+
declare function getPageItems(page: number, pageCount: number): (number | 'ellipsis')[];
|
|
50
|
+
declare function SDSPagination({ page, pageSize, totalItems, onPageChange, onPageSizeChange, showRowsPerPage, pageSizeOptions, resultsSummary, className, }: SDSPaginationProps): React.JSX.Element;
|
|
51
|
+
|
|
52
|
+
export { SDSButton, type SDSButtonProps, SDSInput, type SDSInputProps, type SDSInputStatus, type SDSInputType, SDSPagination, type SDSPaginationProps, getPageItems };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ButtonHTMLAttributes, ReactNode, ChangeEvent, FocusEvent } from 'react';
|
|
3
|
+
import { ButtonAppearance } from '@mrcaktuz/sds-tokens';
|
|
4
|
+
|
|
5
|
+
type SDSButtonProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'color'> & ButtonAppearance & {
|
|
6
|
+
small?: boolean;
|
|
7
|
+
icon?: ReactNode;
|
|
8
|
+
iconPosition?: 'left' | 'right';
|
|
9
|
+
/** Hides the text — set `aria-label` */
|
|
10
|
+
iconOnly?: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare function SDSButton({ variant, color, small, icon, iconPosition, iconOnly, type, className, children, ...props }: SDSButtonProps): React.JSX.Element;
|
|
13
|
+
|
|
14
|
+
type SDSInputType = 'text' | 'email' | 'password' | 'number' | 'tel' | 'url' | 'search' | 'date';
|
|
15
|
+
/** "success" does not exist in the legacy DS: same rendering as "error", with the success color */
|
|
16
|
+
type SDSInputStatus = 'default' | 'error' | 'success';
|
|
17
|
+
type SDSInputProps = {
|
|
18
|
+
/** HTML id of the input, also links the label. Generated when missing */
|
|
19
|
+
id?: string;
|
|
20
|
+
type?: SDSInputType;
|
|
21
|
+
label?: string;
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
/** Fills the field and updates it when it changes */
|
|
24
|
+
value?: string;
|
|
25
|
+
status?: SDSInputStatus;
|
|
26
|
+
/** Shown under the field for the "error" and "success" statuses */
|
|
27
|
+
message?: string;
|
|
28
|
+
/** Called on each keystroke, with the new value */
|
|
29
|
+
onChange?: (value: string, event: ChangeEvent<HTMLInputElement>) => void;
|
|
30
|
+
/** Called when the field loses focus, with the current value */
|
|
31
|
+
onBlur?: (value: string, event: FocusEvent<HTMLInputElement>) => void;
|
|
32
|
+
};
|
|
33
|
+
declare function SDSInput({ id, type, label, placeholder, value, status, message, onChange, onBlur, }: SDSInputProps): React.JSX.Element;
|
|
34
|
+
|
|
35
|
+
type SDSPaginationProps = {
|
|
36
|
+
/** Current page, starting at 1 */
|
|
37
|
+
page: number;
|
|
38
|
+
pageSize: number;
|
|
39
|
+
totalItems: number;
|
|
40
|
+
onPageChange: (page: number) => void;
|
|
41
|
+
onPageSizeChange?: (pageSize: number) => void;
|
|
42
|
+
/** Figma "Show rows per page" */
|
|
43
|
+
showRowsPerPage?: boolean;
|
|
44
|
+
pageSizeOptions?: number[];
|
|
45
|
+
/** Figma "Results summary": replaces the default "1–15 sur 100" */
|
|
46
|
+
resultsSummary?: (from: number, to: number, total: number) => string;
|
|
47
|
+
className?: string;
|
|
48
|
+
};
|
|
49
|
+
declare function getPageItems(page: number, pageCount: number): (number | 'ellipsis')[];
|
|
50
|
+
declare function SDSPagination({ page, pageSize, totalItems, onPageChange, onPageSizeChange, showRowsPerPage, pageSizeOptions, resultsSummary, className, }: SDSPaginationProps): React.JSX.Element;
|
|
51
|
+
|
|
52
|
+
export { SDSButton, type SDSButtonProps, SDSInput, type SDSInputProps, type SDSInputStatus, type SDSInputType, SDSPagination, type SDSPaginationProps, getPageItems };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// src/components/button/button.tsx
|
|
2
|
+
import {
|
|
3
|
+
defaultButtonColor,
|
|
4
|
+
defaultButtonVariant
|
|
5
|
+
} from "@mrcaktuz/sds-tokens";
|
|
6
|
+
import "@mrcaktuz/sds-styles/theme.css";
|
|
7
|
+
import "@mrcaktuz/sds-styles/components/button.css";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
function SDSButton({
|
|
10
|
+
variant = defaultButtonVariant,
|
|
11
|
+
color = defaultButtonColor,
|
|
12
|
+
small = false,
|
|
13
|
+
icon,
|
|
14
|
+
iconPosition = "left",
|
|
15
|
+
iconOnly = false,
|
|
16
|
+
type = "button",
|
|
17
|
+
className,
|
|
18
|
+
children,
|
|
19
|
+
...props
|
|
20
|
+
}) {
|
|
21
|
+
const classes = [
|
|
22
|
+
"sds-btn",
|
|
23
|
+
`sds-btn--${variant}--${color}`,
|
|
24
|
+
small && "sds-btn--small",
|
|
25
|
+
iconOnly && "sds-btn--iconOnly",
|
|
26
|
+
icon && `sds-btn__icon--${iconPosition}`,
|
|
27
|
+
className
|
|
28
|
+
].filter(Boolean).join(" ");
|
|
29
|
+
return /* @__PURE__ */ jsxs("button", { type, className: classes, ...props, children: [
|
|
30
|
+
icon && /* @__PURE__ */ jsx("span", { className: "sds-icon", "aria-hidden": "true", children: icon }),
|
|
31
|
+
children && /* @__PURE__ */ jsx("span", { className: "sds-btn__text", children })
|
|
32
|
+
] });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/components/input/input.tsx
|
|
36
|
+
import { useEffect, useId, useState } from "react";
|
|
37
|
+
import "@mrcaktuz/sds-styles/components/input.css";
|
|
38
|
+
import "@mrcaktuz/sds-styles/theme.css";
|
|
39
|
+
|
|
40
|
+
// src/components/input/input-icons.tsx
|
|
41
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
42
|
+
var CircleAlertIcon = () => /* @__PURE__ */ jsxs2("svg", { className: "sds-input__icon", viewBox: "0 0 16 16", "aria-hidden": "true", children: [
|
|
43
|
+
/* @__PURE__ */ jsx2("path", { d: "M14.1663 8C14.1663 4.59435 11.4059 1.83318 8.00024 1.83301C4.59449 1.83301 1.83325 4.59424 1.83325 8C1.83343 11.4056 4.5946 14.166 8.00024 14.166C11.4057 14.1658 14.1661 11.4055 14.1663 8ZM15.1663 8C15.1661 11.9578 11.958 15.1658 8.00024 15.166C4.04231 15.166 0.833428 11.9579 0.833252 8C0.833252 4.04196 4.0422 0.833008 8.00024 0.833008C11.9581 0.833184 15.1663 4.04207 15.1663 8Z" }),
|
|
44
|
+
/* @__PURE__ */ jsx2("path", { d: "M7.5 8V5.33301C7.5 5.05687 7.72386 4.83301 8 4.83301C8.27614 4.83301 8.5 5.05687 8.5 5.33301V8C8.49982 8.27599 8.27603 8.5 8 8.5C7.72397 8.5 7.50018 8.27599 7.5 8Z" }),
|
|
45
|
+
/* @__PURE__ */ jsx2("path", { d: "M8.00684 10.167C8.2829 10.1671 8.50684 10.3909 8.50684 10.667C8.50684 10.9431 8.2829 11.1669 8.00684 11.167H8C7.72386 11.167 7.5 10.9431 7.5 10.667C7.5 10.3908 7.72386 10.167 8 10.167H8.00684Z" })
|
|
46
|
+
] });
|
|
47
|
+
var CheckmarkOutlineIcon = () => /* @__PURE__ */ jsxs2("svg", { className: "sds-input__icon", viewBox: "0 0 16 16", "aria-hidden": "true", children: [
|
|
48
|
+
/* @__PURE__ */ jsx2("path", { d: "M7 10.707L4.5 8.2065L5.2065 7.5L7 9.293L10.7925 5.5L11.5 6.2075L7 10.707Z" }),
|
|
49
|
+
/* @__PURE__ */ jsx2("path", { d: "M8 1C6.61553 1 5.26216 1.41054 4.11101 2.17971C2.95987 2.94888 2.06266 4.04213 1.53285 5.32122C1.00303 6.6003 0.86441 8.00776 1.13451 9.36563C1.4046 10.7235 2.07129 11.9708 3.05026 12.9497C4.02922 13.9287 5.2765 14.5954 6.63437 14.8655C7.99224 15.1356 9.3997 14.997 10.6788 14.4672C11.9579 13.9373 13.0511 13.0401 13.8203 11.889C14.5895 10.7378 15 9.38447 15 8C15 6.14348 14.2625 4.36301 12.9497 3.05025C11.637 1.7375 9.85652 1 8 1ZM8 14C6.81332 14 5.65328 13.6481 4.66658 12.9888C3.67989 12.3295 2.91085 11.3925 2.45673 10.2961C2.0026 9.19974 1.88378 7.99334 2.11529 6.82946C2.3468 5.66557 2.91825 4.59647 3.75736 3.75736C4.59648 2.91824 5.66558 2.3468 6.82946 2.11529C7.99335 1.88378 9.19975 2.0026 10.2961 2.45672C11.3925 2.91085 12.3295 3.67988 12.9888 4.66658C13.6481 5.65327 14 6.81331 14 8C14 9.5913 13.3679 11.1174 12.2426 12.2426C11.1174 13.3679 9.5913 14 8 14Z" })
|
|
50
|
+
] });
|
|
51
|
+
|
|
52
|
+
// src/components/input/input.tsx
|
|
53
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
54
|
+
function SDSInput({
|
|
55
|
+
id,
|
|
56
|
+
type = "text",
|
|
57
|
+
label,
|
|
58
|
+
placeholder,
|
|
59
|
+
value,
|
|
60
|
+
status = "default",
|
|
61
|
+
message,
|
|
62
|
+
onChange,
|
|
63
|
+
onBlur
|
|
64
|
+
}) {
|
|
65
|
+
const generatedId = useId();
|
|
66
|
+
const inputId = id ?? generatedId;
|
|
67
|
+
const messageId = `${inputId}-message`;
|
|
68
|
+
const showMessage = status !== "default" && !!message;
|
|
69
|
+
const [currentValue, setCurrentValue] = useState(value ?? "");
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (value !== void 0) setCurrentValue(value);
|
|
72
|
+
}, [value]);
|
|
73
|
+
return /* @__PURE__ */ jsxs3("div", { className: `sds-input sds-input--${status}`, children: [
|
|
74
|
+
label && /* @__PURE__ */ jsx3("label", { htmlFor: inputId, className: "sds-input__label", children: label }),
|
|
75
|
+
/* @__PURE__ */ jsxs3("div", { className: "sds-input__container", children: [
|
|
76
|
+
/* @__PURE__ */ jsx3(
|
|
77
|
+
"input",
|
|
78
|
+
{
|
|
79
|
+
id: inputId,
|
|
80
|
+
type,
|
|
81
|
+
placeholder,
|
|
82
|
+
value: currentValue,
|
|
83
|
+
"aria-invalid": status === "error" || void 0,
|
|
84
|
+
"aria-describedby": showMessage ? messageId : void 0,
|
|
85
|
+
onChange: (event) => {
|
|
86
|
+
setCurrentValue(event.target.value);
|
|
87
|
+
onChange?.(event.target.value, event);
|
|
88
|
+
},
|
|
89
|
+
onBlur: (event) => onBlur?.(event.target.value, event)
|
|
90
|
+
}
|
|
91
|
+
),
|
|
92
|
+
status === "error" && /* @__PURE__ */ jsx3(CircleAlertIcon, {}),
|
|
93
|
+
status === "success" && /* @__PURE__ */ jsx3(CheckmarkOutlineIcon, {})
|
|
94
|
+
] }),
|
|
95
|
+
showMessage && /* @__PURE__ */ jsx3("p", { id: messageId, className: "sds-input__message", children: message })
|
|
96
|
+
] });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/components/pagination/pagination.tsx
|
|
100
|
+
import { useId as useId2 } from "react";
|
|
101
|
+
import "@mrcaktuz/sds-styles/components/pagination.css";
|
|
102
|
+
import "@mrcaktuz/sds-styles/theme.css";
|
|
103
|
+
|
|
104
|
+
// src/components/pagination/pagination-icons.tsx
|
|
105
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
106
|
+
var base = {
|
|
107
|
+
width: 16,
|
|
108
|
+
height: 16,
|
|
109
|
+
viewBox: "0 0 24 24",
|
|
110
|
+
fill: "none",
|
|
111
|
+
stroke: "currentColor",
|
|
112
|
+
strokeWidth: 2,
|
|
113
|
+
strokeLinecap: "round",
|
|
114
|
+
strokeLinejoin: "round",
|
|
115
|
+
"aria-hidden": true
|
|
116
|
+
};
|
|
117
|
+
var ChevronLeft = () => /* @__PURE__ */ jsx4("svg", { ...base, children: /* @__PURE__ */ jsx4("path", { d: "m15 18-6-6 6-6" }) });
|
|
118
|
+
var ChevronRight = () => /* @__PURE__ */ jsx4("svg", { ...base, children: /* @__PURE__ */ jsx4("path", { d: "m9 18 6-6-6-6" }) });
|
|
119
|
+
var FirstPage = () => /* @__PURE__ */ jsx4("svg", { ...base, children: /* @__PURE__ */ jsx4("path", { d: "M6 6v12M17 18l-6-6 6-6" }) });
|
|
120
|
+
var LastPage = () => /* @__PURE__ */ jsx4("svg", { ...base, children: /* @__PURE__ */ jsx4("path", { d: "M18 6v12M7 18l6-6-6-6" }) });
|
|
121
|
+
|
|
122
|
+
// src/components/pagination/pagination.tsx
|
|
123
|
+
import { Fragment, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
124
|
+
function getPageItems(page, pageCount) {
|
|
125
|
+
if (pageCount <= 7) return Array.from({ length: pageCount }, (_, i) => i + 1);
|
|
126
|
+
if (page <= 4) return [1, 2, 3, 4, 5, "ellipsis", pageCount];
|
|
127
|
+
if (page >= pageCount - 3)
|
|
128
|
+
return [1, "ellipsis", ...Array.from({ length: 5 }, (_, i) => pageCount - 4 + i)];
|
|
129
|
+
return [1, "ellipsis", page - 1, page, page + 1, "ellipsis", pageCount];
|
|
130
|
+
}
|
|
131
|
+
function SDSPagination({
|
|
132
|
+
page,
|
|
133
|
+
pageSize,
|
|
134
|
+
totalItems,
|
|
135
|
+
onPageChange,
|
|
136
|
+
onPageSizeChange,
|
|
137
|
+
showRowsPerPage = true,
|
|
138
|
+
pageSizeOptions = [15, 30, 50],
|
|
139
|
+
resultsSummary = (from, to, total) => `${from}\u2013${to} sur ${total}`,
|
|
140
|
+
className
|
|
141
|
+
}) {
|
|
142
|
+
const selectId = useId2();
|
|
143
|
+
const pageCount = Math.max(1, Math.ceil(totalItems / pageSize));
|
|
144
|
+
const from = totalItems === 0 ? 0 : (page - 1) * pageSize + 1;
|
|
145
|
+
const to = Math.min(page * pageSize, totalItems);
|
|
146
|
+
const isFirst = page <= 1;
|
|
147
|
+
const isLast = page >= pageCount;
|
|
148
|
+
return /* @__PURE__ */ jsxs4("div", { className: ["sds-pagination", className].filter(Boolean).join(" "), children: [
|
|
149
|
+
/* @__PURE__ */ jsxs4("div", { className: "sds-pagination__summary", children: [
|
|
150
|
+
showRowsPerPage && /* @__PURE__ */ jsxs4(Fragment, { children: [
|
|
151
|
+
/* @__PURE__ */ jsx5("label", { htmlFor: selectId, className: "sds-pagination__label", children: "Lignes par page" }),
|
|
152
|
+
/* @__PURE__ */ jsx5(
|
|
153
|
+
"select",
|
|
154
|
+
{
|
|
155
|
+
id: selectId,
|
|
156
|
+
className: "sds-pagination__select",
|
|
157
|
+
value: pageSize,
|
|
158
|
+
onChange: (e) => onPageSizeChange?.(Number(e.target.value)),
|
|
159
|
+
children: pageSizeOptions.map((size) => /* @__PURE__ */ jsx5("option", { value: size, children: size }, size))
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
] }),
|
|
163
|
+
/* @__PURE__ */ jsx5("span", { className: "sds-pagination__results", "aria-live": "polite", children: resultsSummary(from, to, totalItems) })
|
|
164
|
+
] }),
|
|
165
|
+
/* @__PURE__ */ jsxs4("nav", { className: "sds-pagination__nav", "aria-label": "Pagination", children: [
|
|
166
|
+
/* @__PURE__ */ jsx5(
|
|
167
|
+
"button",
|
|
168
|
+
{
|
|
169
|
+
type: "button",
|
|
170
|
+
className: "sds-pagination__btn",
|
|
171
|
+
"aria-label": "Premi\xE8re page",
|
|
172
|
+
disabled: isFirst,
|
|
173
|
+
onClick: () => onPageChange(1),
|
|
174
|
+
children: /* @__PURE__ */ jsx5(FirstPage, {})
|
|
175
|
+
}
|
|
176
|
+
),
|
|
177
|
+
/* @__PURE__ */ jsx5(
|
|
178
|
+
"button",
|
|
179
|
+
{
|
|
180
|
+
type: "button",
|
|
181
|
+
className: "sds-pagination__btn",
|
|
182
|
+
"aria-label": "Page pr\xE9c\xE9dente",
|
|
183
|
+
disabled: isFirst,
|
|
184
|
+
onClick: () => onPageChange(page - 1),
|
|
185
|
+
children: /* @__PURE__ */ jsx5(ChevronLeft, {})
|
|
186
|
+
}
|
|
187
|
+
),
|
|
188
|
+
getPageItems(page, pageCount).map(
|
|
189
|
+
(item, i) => item === "ellipsis" ? /* @__PURE__ */ jsx5("span", { className: "sds-pagination__ellipsis", "aria-hidden": "true", children: "\u2026" }, `e${i}`) : /* @__PURE__ */ jsx5(
|
|
190
|
+
"button",
|
|
191
|
+
{
|
|
192
|
+
type: "button",
|
|
193
|
+
className: "sds-pagination__btn sds-pagination__page",
|
|
194
|
+
"aria-label": `Page ${item}`,
|
|
195
|
+
"aria-current": item === page ? "page" : void 0,
|
|
196
|
+
onClick: () => onPageChange(item),
|
|
197
|
+
children: item
|
|
198
|
+
},
|
|
199
|
+
item
|
|
200
|
+
)
|
|
201
|
+
),
|
|
202
|
+
/* @__PURE__ */ jsx5(
|
|
203
|
+
"button",
|
|
204
|
+
{
|
|
205
|
+
type: "button",
|
|
206
|
+
className: "sds-pagination__btn",
|
|
207
|
+
"aria-label": "Page suivante",
|
|
208
|
+
disabled: isLast,
|
|
209
|
+
onClick: () => onPageChange(page + 1),
|
|
210
|
+
children: /* @__PURE__ */ jsx5(ChevronRight, {})
|
|
211
|
+
}
|
|
212
|
+
),
|
|
213
|
+
/* @__PURE__ */ jsx5(
|
|
214
|
+
"button",
|
|
215
|
+
{
|
|
216
|
+
type: "button",
|
|
217
|
+
className: "sds-pagination__btn",
|
|
218
|
+
"aria-label": "Derni\xE8re page",
|
|
219
|
+
disabled: isLast,
|
|
220
|
+
onClick: () => onPageChange(pageCount),
|
|
221
|
+
children: /* @__PURE__ */ jsx5(LastPage, {})
|
|
222
|
+
}
|
|
223
|
+
)
|
|
224
|
+
] })
|
|
225
|
+
] });
|
|
226
|
+
}
|
|
227
|
+
export {
|
|
228
|
+
SDSButton,
|
|
229
|
+
SDSInput,
|
|
230
|
+
SDSPagination,
|
|
231
|
+
getPageItems
|
|
232
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrcaktuz/sds-react",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"description": "Synerglass Design System — React components, styled on import",
|
|
4
|
+
"version": "0.1.1",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./grid": {
|
|
17
|
+
"types": "./dist/grid.d.ts",
|
|
18
|
+
"import": "./dist/grid.js",
|
|
19
|
+
"require": "./dist/grid.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react": ">=19 <20",
|
|
28
|
+
"react-dom": ">=19 <20",
|
|
29
|
+
"@vaadin/react-components": "~25.3.5"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@lit/react": "^1.0.8",
|
|
33
|
+
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
34
|
+
"lit": "^3.3.1",
|
|
35
|
+
"@mrcaktuz/sds-styles": "0.1.0",
|
|
36
|
+
"@mrcaktuz/sds-tokens": "0.1.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/react": "^19.3.0",
|
|
40
|
+
"@vaadin/react-components": "25.3.5",
|
|
41
|
+
"react": "^19.3.1",
|
|
42
|
+
"tsup": "^8.5.1",
|
|
43
|
+
"typescript": "^5.9.3"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"fork": "node scripts/fork-vaadin.mjs grid",
|
|
47
|
+
"build": "node scripts/fork-vaadin.mjs grid && tsup",
|
|
48
|
+
"dev": "node scripts/fork-vaadin.mjs grid && tsup --watch",
|
|
49
|
+
"typecheck": "node scripts/fork-vaadin.mjs grid && tsc --noEmit"
|
|
50
|
+
}
|
|
6
51
|
}
|