anicca-ui 1.0.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 +21 -0
- package/README.md +371 -0
- package/dist/anicca-ui.css +1 -0
- package/dist/anicca-ui.es.js +927 -0
- package/dist/anicca-ui.umd.js +1 -0
- package/dist/dashboard/components/ActivityFeed/ActivityFeed.d.ts +27 -0
- package/dist/dashboard/components/ActivityFeed/index.d.ts +2 -0
- package/dist/dashboard/components/Breadcrumb/Breadcrumb.d.ts +25 -0
- package/dist/dashboard/components/Breadcrumb/index.d.ts +2 -0
- package/dist/dashboard/components/ChartWrapper/ChartWrapper.d.ts +34 -0
- package/dist/dashboard/components/ChartWrapper/index.d.ts +2 -0
- package/dist/dashboard/components/DataTable/DataTable.d.ts +38 -0
- package/dist/dashboard/components/DataTable/index.d.ts +2 -0
- package/dist/dashboard/components/Modal/Modal.d.ts +28 -0
- package/dist/dashboard/components/Modal/index.d.ts +2 -0
- package/dist/dashboard/components/Navbar/Navbar.d.ts +31 -0
- package/dist/dashboard/components/Navbar/index.d.ts +2 -0
- package/dist/dashboard/components/ProgressCard/ProgressCard.d.ts +39 -0
- package/dist/dashboard/components/ProgressCard/index.d.ts +2 -0
- package/dist/dashboard/components/Sidebar/Sidebar.d.ts +36 -0
- package/dist/dashboard/components/Sidebar/index.d.ts +2 -0
- package/dist/dashboard/components/StatCard/StatCard.d.ts +26 -0
- package/dist/dashboard/components/StatCard/index.d.ts +2 -0
- package/dist/dashboard/components/Tabs/Tabs.d.ts +28 -0
- package/dist/dashboard/components/Tabs/index.d.ts +2 -0
- package/dist/dashboard/index.d.ts +11 -0
- package/dist/date/hooks/useAniccaDate/index.d.ts +2 -0
- package/dist/date/hooks/useAniccaDate/useAniccaDate.d.ts +42 -0
- package/dist/date/index.d.ts +2 -0
- package/dist/date/utils/index.d.ts +82 -0
- package/dist/index.d.ts +6 -0
- package/dist/theme/AniccaThemeProvider.d.ts +27 -0
- package/dist/theme/index.d.ts +5 -0
- package/dist/theme/types.d.ts +39 -0
- package/dist/utils/functions/index.d.ts +109 -0
- package/dist/utils/hooks/useAniccaUtils/index.d.ts +2 -0
- package/dist/utils/hooks/useAniccaUtils/useAniccaUtils.d.ts +40 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/validation/hooks/useAniccaForm/index.d.ts +2 -0
- package/dist/validation/hooks/useAniccaForm/useAniccaForm.d.ts +60 -0
- package/dist/validation/index.d.ts +2 -0
- package/dist/validation/rules/index.d.ts +73 -0
- package/package.json +65 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AniccaTheme — Token overrides for the AniccaUI design system.
|
|
3
|
+
*
|
|
4
|
+
* Pass partial values to `AniccaThemeProvider` to rebrand components
|
|
5
|
+
* without touching CSS. Any token omitted keeps the library default.
|
|
6
|
+
*/
|
|
7
|
+
export interface AniccaTheme {
|
|
8
|
+
primary?: string;
|
|
9
|
+
primaryFg?: string;
|
|
10
|
+
primarySoft?: string;
|
|
11
|
+
success?: string;
|
|
12
|
+
successBg?: string;
|
|
13
|
+
danger?: string;
|
|
14
|
+
dangerBg?: string;
|
|
15
|
+
warning?: string;
|
|
16
|
+
warningBg?: string;
|
|
17
|
+
info?: string;
|
|
18
|
+
infoBg?: string;
|
|
19
|
+
surface?: string;
|
|
20
|
+
surfaceMuted?: string;
|
|
21
|
+
surfaceOverlay?: string;
|
|
22
|
+
surfaceDark?: string;
|
|
23
|
+
surfaceDark2?: string;
|
|
24
|
+
surfaceDarkFg?: string;
|
|
25
|
+
surfaceDarkFgMuted?: string;
|
|
26
|
+
border?: string;
|
|
27
|
+
borderStrong?: string;
|
|
28
|
+
borderDark?: string;
|
|
29
|
+
text?: string;
|
|
30
|
+
textMuted?: string;
|
|
31
|
+
textSubtle?: string;
|
|
32
|
+
radius?: string;
|
|
33
|
+
radiusSm?: string;
|
|
34
|
+
radiusLg?: string;
|
|
35
|
+
shadowSm?: string;
|
|
36
|
+
shadowMd?: string;
|
|
37
|
+
shadowLg?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare const ANICCA_THEME_CSS_VAR_MAP: Record<keyof AniccaTheme, string>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a debounced version of a function that delays execution
|
|
3
|
+
* until after the specified delay has elapsed since the last call.
|
|
4
|
+
*
|
|
5
|
+
* @param fn - Function to debounce
|
|
6
|
+
* @param delay - Delay in milliseconds
|
|
7
|
+
* @returns Debounced function
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const debouncedSearch = aniccaDebounce((query) => search(query), 300)
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare function aniccaDebounce<T extends (...args: never[]) => unknown>(fn: T, delay: number): (...args: Parameters<T>) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a throttled version of a function that executes
|
|
17
|
+
* at most once per specified time limit.
|
|
18
|
+
*
|
|
19
|
+
* @param fn - Function to throttle
|
|
20
|
+
* @param limit - Minimum interval in milliseconds
|
|
21
|
+
* @returns Throttled function
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const throttledScroll = aniccaThrottle(handleScroll, 200)
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function aniccaThrottle<T extends (...args: never[]) => unknown>(fn: T, limit: number): (...args: Parameters<T>) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Truncates a string to the specified length and appends a suffix.
|
|
31
|
+
*
|
|
32
|
+
* @param str - String to truncate
|
|
33
|
+
* @param length - Maximum length before truncation
|
|
34
|
+
* @param suffix - Suffix to append (default: "...")
|
|
35
|
+
* @returns Truncated string
|
|
36
|
+
*/
|
|
37
|
+
export declare function aniccaTruncate(str: string, length: number, suffix?: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Copies text to the clipboard using the Clipboard API with
|
|
40
|
+
* a fallback to execCommand for older browsers.
|
|
41
|
+
*
|
|
42
|
+
* @param text - Text to copy
|
|
43
|
+
* @returns Promise resolving to true on success, false on failure
|
|
44
|
+
*/
|
|
45
|
+
export declare function aniccaCopyToClipboard(text: string): Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* Converts a string to a URL-friendly slug.
|
|
48
|
+
*
|
|
49
|
+
* @param str - String to slugify
|
|
50
|
+
* @returns Slugified string
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* aniccaSlugify('Hello World!') // "hello-world"
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function aniccaSlugify(str: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Capitalizes the first letter of a string and lowercases the rest.
|
|
60
|
+
*
|
|
61
|
+
* @param str - String to capitalize
|
|
62
|
+
* @returns Capitalized string
|
|
63
|
+
*/
|
|
64
|
+
export declare function aniccaCapitalize(str: string): string;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a deep clone of an object.
|
|
67
|
+
* Uses structuredClone if available, falls back to JSON serialization.
|
|
68
|
+
*
|
|
69
|
+
* @param obj - Object to clone
|
|
70
|
+
* @returns Deep clone of the object
|
|
71
|
+
*/
|
|
72
|
+
export declare function aniccaDeepClone<T>(obj: T): T;
|
|
73
|
+
/**
|
|
74
|
+
* Flattens a nested object into a single-level object with dot-notation keys.
|
|
75
|
+
*
|
|
76
|
+
* @param obj - Object to flatten
|
|
77
|
+
* @param prefix - Key prefix for recursion
|
|
78
|
+
* @returns Flattened object
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* aniccaFlattenObject({ a: { b: { c: 1 } } })
|
|
83
|
+
* // { 'a.b.c': 1 }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function aniccaFlattenObject(obj: Record<string, unknown>, prefix?: string): Record<string, unknown>;
|
|
87
|
+
/**
|
|
88
|
+
* Groups an array of objects by a specified key.
|
|
89
|
+
*
|
|
90
|
+
* @param array - Array to group
|
|
91
|
+
* @param key - Key to group by
|
|
92
|
+
* @returns Object with grouped arrays
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* aniccaGroupBy([{ role: 'admin', name: 'A' }, { role: 'user', name: 'B' }], 'role')
|
|
97
|
+
* // { admin: [{ role: 'admin', name: 'A' }], user: [{ role: 'user', name: 'B' }] }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function aniccaGroupBy<T>(array: T[], key: keyof T): Record<string, T[]>;
|
|
101
|
+
/**
|
|
102
|
+
* Returns a new array with duplicates removed based on a key property.
|
|
103
|
+
* Keeps the first occurrence of each unique key value.
|
|
104
|
+
*
|
|
105
|
+
* @param array - Array to deduplicate
|
|
106
|
+
* @param key - Key to check for uniqueness
|
|
107
|
+
* @returns Deduplicated array
|
|
108
|
+
*/
|
|
109
|
+
export declare function aniccaUniqueBy<T>(array: T[], key: keyof T): T[];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { aniccaDebounce, aniccaThrottle, aniccaTruncate, aniccaCopyToClipboard, aniccaSlugify, aniccaCapitalize, aniccaDeepClone, aniccaFlattenObject, aniccaGroupBy, aniccaUniqueBy } from '../../functions';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Return type for useAniccaUtils hook.
|
|
5
|
+
*/
|
|
6
|
+
export interface UseAniccaUtilsReturn {
|
|
7
|
+
/** Create a debounced function */
|
|
8
|
+
debounce: typeof aniccaDebounce;
|
|
9
|
+
/** Create a throttled function */
|
|
10
|
+
throttle: typeof aniccaThrottle;
|
|
11
|
+
/** Truncate a string */
|
|
12
|
+
truncate: typeof aniccaTruncate;
|
|
13
|
+
/** Copy text to clipboard */
|
|
14
|
+
copyToClipboard: typeof aniccaCopyToClipboard;
|
|
15
|
+
/** Convert string to slug */
|
|
16
|
+
slugify: typeof aniccaSlugify;
|
|
17
|
+
/** Capitalize first letter */
|
|
18
|
+
capitalize: typeof aniccaCapitalize;
|
|
19
|
+
/** Deep clone an object */
|
|
20
|
+
deepClone: typeof aniccaDeepClone;
|
|
21
|
+
/** Flatten nested object */
|
|
22
|
+
flattenObject: typeof aniccaFlattenObject;
|
|
23
|
+
/** Group array by key */
|
|
24
|
+
groupBy: typeof aniccaGroupBy;
|
|
25
|
+
/** Remove duplicates by key */
|
|
26
|
+
uniqueBy: typeof aniccaUniqueBy;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* useAniccaUtils — A hook that provides access to all utility functions
|
|
30
|
+
* as a memoized object for convenient use in React components.
|
|
31
|
+
*
|
|
32
|
+
* @returns Object containing all utility functions
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* const { slugify, truncate, copyToClipboard } = useAniccaUtils()
|
|
37
|
+
* const slug = slugify('Hello World')
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function useAniccaUtils(): UseAniccaUtilsReturn;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ValidationRule } from '../../rules';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for useAniccaForm hook.
|
|
5
|
+
*/
|
|
6
|
+
export interface UseAniccaFormConfig<T extends Record<string, unknown>> {
|
|
7
|
+
/** Initial form values */
|
|
8
|
+
initialValues: T;
|
|
9
|
+
/** Validation schema mapping field names to validation rules */
|
|
10
|
+
validationSchema?: Partial<Record<keyof T, ValidationRule[]>>;
|
|
11
|
+
/** Submit handler called with valid form values */
|
|
12
|
+
onSubmit?: (values: T) => void | Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Return type for useAniccaForm hook.
|
|
16
|
+
*/
|
|
17
|
+
export interface UseAniccaFormReturn<T extends Record<string, unknown>> {
|
|
18
|
+
/** Current form values */
|
|
19
|
+
values: T;
|
|
20
|
+
/** Current field errors */
|
|
21
|
+
errors: Partial<Record<keyof T, string>>;
|
|
22
|
+
/** Fields that have been touched (blurred) */
|
|
23
|
+
touched: Partial<Record<keyof T, boolean>>;
|
|
24
|
+
/** Whether the form is currently valid (no errors) */
|
|
25
|
+
isValid: boolean;
|
|
26
|
+
/** Whether the form is currently submitting */
|
|
27
|
+
isSubmitting: boolean;
|
|
28
|
+
/** Returns a change handler for a specific field */
|
|
29
|
+
handleChange: (field: keyof T) => (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
|
|
30
|
+
/** Returns a blur handler for a specific field */
|
|
31
|
+
handleBlur: (field: keyof T) => () => void;
|
|
32
|
+
/** Submit handler (validates all fields first) */
|
|
33
|
+
handleSubmit: (e?: React.FormEvent) => Promise<void>;
|
|
34
|
+
/** Reset form to initial values */
|
|
35
|
+
reset: () => void;
|
|
36
|
+
/** Set a specific field value programmatically */
|
|
37
|
+
setFieldValue: (field: keyof T, value: unknown) => void;
|
|
38
|
+
/** Set a specific field error programmatically */
|
|
39
|
+
setFieldError: (field: keyof T, error: string) => void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* useAniccaForm — A comprehensive form state management hook with
|
|
43
|
+
* field-level validation, touch tracking, and async submit support.
|
|
44
|
+
*
|
|
45
|
+
* @param config - Form configuration with initial values, validation schema, and submit handler
|
|
46
|
+
* @returns Form state and handler methods
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* const form = useAniccaForm({
|
|
51
|
+
* initialValues: { email: '', password: '' },
|
|
52
|
+
* validationSchema: {
|
|
53
|
+
* email: [required(), email()],
|
|
54
|
+
* password: [required(), minLength(8)],
|
|
55
|
+
* },
|
|
56
|
+
* onSubmit: async (values) => { await login(values) },
|
|
57
|
+
* })
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function useAniccaForm<T extends Record<string, unknown>>(config: UseAniccaFormConfig<T>): UseAniccaFormReturn<T>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A validation rule consisting of a validate function and error message.
|
|
3
|
+
*/
|
|
4
|
+
export interface ValidationRule {
|
|
5
|
+
/** Validation function that returns true if valid */
|
|
6
|
+
validate: (value: unknown) => boolean;
|
|
7
|
+
/** Error message when validation fails */
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates a required validation rule.
|
|
12
|
+
* Fails if value is null, undefined, empty string, or empty array.
|
|
13
|
+
*
|
|
14
|
+
* @param message - Custom error message
|
|
15
|
+
* @returns ValidationRule
|
|
16
|
+
*/
|
|
17
|
+
export declare function required(message?: string): ValidationRule;
|
|
18
|
+
/**
|
|
19
|
+
* Creates an email validation rule.
|
|
20
|
+
* Fails if value does not match standard email format.
|
|
21
|
+
*
|
|
22
|
+
* @param message - Custom error message
|
|
23
|
+
* @returns ValidationRule
|
|
24
|
+
*/
|
|
25
|
+
export declare function email(message?: string): ValidationRule;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a minimum length validation rule.
|
|
28
|
+
*
|
|
29
|
+
* @param min - Minimum string length
|
|
30
|
+
* @param message - Custom error message
|
|
31
|
+
* @returns ValidationRule
|
|
32
|
+
*/
|
|
33
|
+
export declare function minLength(min: number, message?: string): ValidationRule;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a maximum length validation rule.
|
|
36
|
+
*
|
|
37
|
+
* @param max - Maximum string length
|
|
38
|
+
* @param message - Custom error message
|
|
39
|
+
* @returns ValidationRule
|
|
40
|
+
*/
|
|
41
|
+
export declare function maxLength(max: number, message?: string): ValidationRule;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a regex pattern validation rule.
|
|
44
|
+
*
|
|
45
|
+
* @param regex - Regular expression to test against
|
|
46
|
+
* @param message - Custom error message
|
|
47
|
+
* @returns ValidationRule
|
|
48
|
+
*/
|
|
49
|
+
export declare function pattern(regex: RegExp, message?: string): ValidationRule;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a minimum value validation rule for numbers.
|
|
52
|
+
*
|
|
53
|
+
* @param value - Minimum allowed value
|
|
54
|
+
* @param message - Custom error message
|
|
55
|
+
* @returns ValidationRule
|
|
56
|
+
*/
|
|
57
|
+
export declare function min(value: number, message?: string): ValidationRule;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a maximum value validation rule for numbers.
|
|
60
|
+
*
|
|
61
|
+
* @param value - Maximum allowed value
|
|
62
|
+
* @param message - Custom error message
|
|
63
|
+
* @returns ValidationRule
|
|
64
|
+
*/
|
|
65
|
+
export declare function max(value: number, message?: string): ValidationRule;
|
|
66
|
+
/**
|
|
67
|
+
* Creates a custom validation rule with a user-provided function.
|
|
68
|
+
*
|
|
69
|
+
* @param fn - Custom validation function
|
|
70
|
+
* @param message - Error message when validation fails
|
|
71
|
+
* @returns ValidationRule
|
|
72
|
+
*/
|
|
73
|
+
export declare function custom(fn: (value: unknown) => boolean, message: string): ValidationRule;
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "anicca-ui",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "A production-ready React utility library with dashboard components, form validation, date manipulation, and general utilities",
|
|
6
|
+
"main": "dist/anicca-ui.umd.js",
|
|
7
|
+
"module": "dist/anicca-ui.es.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/anicca-ui.es.js",
|
|
13
|
+
"require": "./dist/anicca-ui.umd.js"
|
|
14
|
+
},
|
|
15
|
+
"./styles.css": {
|
|
16
|
+
"default": "./dist/anicca-ui.css"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"sideEffects": [
|
|
24
|
+
"**/*.css"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"prebuild": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
28
|
+
"build": "tsc --noEmit && vite build",
|
|
29
|
+
"storybook": "storybook dev -p 6006",
|
|
30
|
+
"build-storybook": "storybook build",
|
|
31
|
+
"prepublishOnly": "npm run build"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"react": ">=18.0.0",
|
|
35
|
+
"react-dom": ">=18.0.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@storybook/addon-essentials": "^8.6.14",
|
|
39
|
+
"@storybook/react-vite": "^8.6.18",
|
|
40
|
+
"@types/react": "^18.2.0",
|
|
41
|
+
"@types/react-dom": "^18.2.0",
|
|
42
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
43
|
+
"autoprefixer": "^10.4.20",
|
|
44
|
+
"postcss": "^8.4.49",
|
|
45
|
+
"react": "^19.2.6",
|
|
46
|
+
"react-dom": "^19.2.6",
|
|
47
|
+
"storybook": "^8.6.18",
|
|
48
|
+
"tailwindcss": "^3.4.17",
|
|
49
|
+
"typescript": "^5.0.0",
|
|
50
|
+
"vite": "^5.0.0",
|
|
51
|
+
"vite-plugin-dts": "^3.0.0"
|
|
52
|
+
},
|
|
53
|
+
"keywords": [
|
|
54
|
+
"react",
|
|
55
|
+
"utility",
|
|
56
|
+
"dashboard",
|
|
57
|
+
"validation",
|
|
58
|
+
"date",
|
|
59
|
+
"hooks"
|
|
60
|
+
],
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
}
|
|
65
|
+
}
|