@cloudwick/astral-ui-cli 2.3.0 → 2.5.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/dist/index.js +362 -540
- package/dist/index.js.map +1 -1
- package/dist/templates/constants/index.ts +10 -0
- package/dist/templates/hooks/index.ts +2 -0
- package/dist/templates/hooks/useLabelPeekDismissal.ts +50 -0
- package/dist/templates/hooks/usePartRegistration.ts +27 -0
- package/dist/templates/tailwind/tailwind.config.js +2 -2
- package/dist/templates/utils/fieldHelperText.tsx +30 -0
- package/dist/templates/utils/index.ts +2 -0
- package/dist/templates/utils/stringUtils/index.tsx +2 -0
- package/dist/templates/utils/stringUtils/joinIds.ts +13 -0
- package/dist/templates/utils/stringUtils/resultsAvailable.ts +11 -0
- package/dist/templates/utils/truncatedLabelReveal.ts +23 -0
- package/package.json +1 -1
|
@@ -2,3 +2,13 @@ export { keyboardKeys } from "./keyboardKey";
|
|
|
2
2
|
|
|
3
3
|
export const mobileBreakPoint = 767;
|
|
4
4
|
export const semanticInteractiveElements = [ "button", "a", "summary", "input", "select", "textarea" ];
|
|
5
|
+
export const focusableSelector = [
|
|
6
|
+
"a[href]",
|
|
7
|
+
"button:not([disabled])",
|
|
8
|
+
"input:not([disabled]):not([type=\"hidden\"])",
|
|
9
|
+
"select:not([disabled])",
|
|
10
|
+
"textarea:not([disabled])",
|
|
11
|
+
"summary",
|
|
12
|
+
"[contenteditable=\"true\"]",
|
|
13
|
+
"[tabindex]:not([tabindex=\"-1\"])"
|
|
14
|
+
].join( "," );
|
|
@@ -18,3 +18,5 @@ export { useIgnoredPropWarning } from "./useIgnoredPropWarning";
|
|
|
18
18
|
export { useOnValueChange } from "./useOnValueChange";
|
|
19
19
|
export { useIsTruncated } from "./useIsTruncated";
|
|
20
20
|
export { useListboxKeyboardNav } from "./useListboxKeyboardNav";
|
|
21
|
+
export { useLabelPeekDismissal } from "./useLabelPeekDismissal";
|
|
22
|
+
export { usePartPresence, usePartRegistration } from "./usePartRegistration";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useEffect, useRef, useState, type RefObject } from "react";
|
|
2
|
+
|
|
3
|
+
import { keyboardKeys } from "@constants";
|
|
4
|
+
|
|
5
|
+
// A truncated label showing its full text, which overlays the rows around it: the hovered row, or the
|
|
6
|
+
// keyboard-active one. `:hover` may be unsupported in jsdom, where nothing is ever hovered anyway.
|
|
7
|
+
const findPeekingLabel = ( list: HTMLElement ): Element | null => {
|
|
8
|
+
try {
|
|
9
|
+
return list.querySelector( "[data-truncated]:hover, [data-truncated][data-active]" );
|
|
10
|
+
} catch {
|
|
11
|
+
return list.querySelector( "[data-truncated][data-active]" );
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Escape dismissal for a list's truncated-label reveal: rows marked `data-truncated` that show their full
|
|
17
|
+
* label over the rows around them while hovered or `data-active`. Escape hides the reveal until the
|
|
18
|
+
* pointer enters another row or the keyboard moves on. It is consumed only while a reveal is showing, so
|
|
19
|
+
* whatever handles Escape around the list (a dropdown, a modal) still sees the Escape that follows.
|
|
20
|
+
*/
|
|
21
|
+
export function useLabelPeekDismissal(
|
|
22
|
+
listRef: RefObject<HTMLElement>,
|
|
23
|
+
activeIndex: number
|
|
24
|
+
): { isPeekDismissed: boolean; restorePeek: () => void } {
|
|
25
|
+
// The active index the dismissal was made at. Moving the keyboard on clears it during render, so the
|
|
26
|
+
// reveal returns without the extra commit an effect would cost.
|
|
27
|
+
const [ dismissedAt, setDismissedAt ] = useState<number | null>( null );
|
|
28
|
+
if ( dismissedAt !== null && dismissedAt !== activeIndex ) {
|
|
29
|
+
setDismissedAt( null );
|
|
30
|
+
}
|
|
31
|
+
const activeIndexRef = useRef( activeIndex );
|
|
32
|
+
activeIndexRef.current = activeIndex;
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const handleKeyDown = ( e: KeyboardEvent ) => {
|
|
36
|
+
const list = listRef.current;
|
|
37
|
+
if ( e.key === keyboardKeys.escape && list && findPeekingLabel( list )) {
|
|
38
|
+
e.stopPropagation();
|
|
39
|
+
setDismissedAt( activeIndexRef.current );
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
document.addEventListener( "keydown", handleKeyDown, true );
|
|
43
|
+
return () => document.removeEventListener( "keydown", handleKeyDown, true );
|
|
44
|
+
}, [listRef]);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
isPeekDismissed: dismissedAt === activeIndex,
|
|
48
|
+
restorePeek: () => setDismissedAt( null )
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Tracks whether any instance of a compound component's part (a title, a header) is rendered. Parts
|
|
5
|
+
* report themselves through `usePartRegistration`, which also finds parts nested in fragments or
|
|
6
|
+
* wrapper components. Instances are counted, so one unmounting doesn't hide another still rendered.
|
|
7
|
+
*/
|
|
8
|
+
export function usePartPresence(): [ boolean, ( mounted: boolean ) => void ] {
|
|
9
|
+
const [ count, setCount ] = useState( 0 );
|
|
10
|
+
const register = useCallback(( mounted: boolean ) => {
|
|
11
|
+
setCount(( current ) => current + ( mounted ? 1 : -1 ));
|
|
12
|
+
}, []);
|
|
13
|
+
return [ count > 0, register ];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Reports a part to the `register` callback from `usePartPresence` while it renders content.
|
|
18
|
+
*/
|
|
19
|
+
export function usePartRegistration( register: (( mounted: boolean ) => void ) | undefined, hasContent: boolean ): void {
|
|
20
|
+
useLayoutEffect(() => {
|
|
21
|
+
if ( !register || !hasContent ) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
register( true );
|
|
25
|
+
return () => register( false );
|
|
26
|
+
}, [ register, hasContent ]);
|
|
27
|
+
}
|
|
@@ -193,11 +193,11 @@ export default {
|
|
|
193
193
|
md: "0 16px 48px -4px rgba(27, 37, 51, 0.06)",
|
|
194
194
|
xl: "0 32px 80px -4px rgba(27, 37, 51, 0.12)",
|
|
195
195
|
xxl: "0 64px 80px -4px rgba(27, 37, 51, 0.12)",
|
|
196
|
-
"primary-2px": "0px 0px
|
|
196
|
+
"primary-2px": "0px 0px 0px 2px rgb(var(--primary-500))",
|
|
197
197
|
"secondary-2px": "0px 0px 2px 2px rgba(214, 218, 225, 1)",
|
|
198
198
|
"success-2px": "0px 0px 2px 2px rgba(163, 214, 201, 1)",
|
|
199
199
|
"warning-2px": "0px 0px 2px 2px rgba(251, 210, 156, 1)",
|
|
200
|
-
"error-2px": "0px 0px
|
|
200
|
+
"error-2px": "0px 0px 0px 2px rgb(var(--error-700))",
|
|
201
201
|
"primary-4px": "0px 0px 0px 4px rgba(204, 229, 253, 1)",
|
|
202
202
|
"secondary-4px": "0px 0px 0px 4px rgba(214, 218, 225, 1)",
|
|
203
203
|
"success-4px": "0px 0px 0px 4px rgba(163, 214, 201, 1)",
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Id of a form control's helper text element, derived from the control's id.
|
|
5
|
+
* @param controlId - id of the form control the helper text describes
|
|
6
|
+
* @returns {string} - the helper text element's id
|
|
7
|
+
*/
|
|
8
|
+
export const getHelperTextId = ( controlId: string ): string => `${controlId}-helper-text`;
|
|
9
|
+
|
|
10
|
+
export interface IFieldHelperTextProps {
|
|
11
|
+
/**
|
|
12
|
+
* Id referenced by the control's `aria-describedby`
|
|
13
|
+
*/
|
|
14
|
+
id: string;
|
|
15
|
+
/**
|
|
16
|
+
* Classes applied while there is helper text to show
|
|
17
|
+
*/
|
|
18
|
+
className: string;
|
|
19
|
+
children?: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Helper text below a form control. It stays mounted, visually hidden while empty, so helper
|
|
24
|
+
* text that appears later (such as a validation error) is announced by the live region.
|
|
25
|
+
*/
|
|
26
|
+
export const FieldHelperText = ({ id, className, children }: IFieldHelperTextProps ): ReactElement => (
|
|
27
|
+
<div id={id} aria-live="polite" className={children ? className : "sr-only"}>
|
|
28
|
+
{children}
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Joins element ids into a space-separated list for ARIA id-reference attributes
|
|
3
|
+
* such as `aria-describedby` and `aria-labelledby`.
|
|
4
|
+
* @param ids - ids to join; empty and undefined values are skipped
|
|
5
|
+
* @returns {string | undefined} - the joined ids, or undefined when none remain
|
|
6
|
+
* @example
|
|
7
|
+
* joinIds("hint", undefined, "error") // returns "hint error"
|
|
8
|
+
* joinIds(undefined, "") // returns undefined
|
|
9
|
+
*/
|
|
10
|
+
export function joinIds( ...ids: ( string | undefined )[]): string | undefined {
|
|
11
|
+
const joined = ids.filter( Boolean ).join( " " );
|
|
12
|
+
return joined || undefined;
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The status-region text a listbox announces for the options it is showing.
|
|
3
|
+
* @param count - how many options are on screen
|
|
4
|
+
* @returns {string} - the announcement
|
|
5
|
+
* @example
|
|
6
|
+
* formatResultsAvailable(1) // returns "1 result available"
|
|
7
|
+
* formatResultsAvailable(3) // returns "3 results available"
|
|
8
|
+
*/
|
|
9
|
+
export function formatResultsAvailable( count: number ): string {
|
|
10
|
+
return `${count} result${count === 1 ? "" : "s"} available`;
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classes for a list row's label that shows its full text over the rows around it when it is clipped.
|
|
3
|
+
* They apply while the row (a `group`) is marked `data-truncated="true"` and is hovered or marked
|
|
4
|
+
* `data-active="true"`; `useLabelPeekDismissal` is the matching Escape dismissal. Append them to the
|
|
5
|
+
* label's base classes, which keep it on one truncated line otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export const truncatedLabelReveal =
|
|
8
|
+
"[.group[data-truncated=true]:is(:hover,[data-active=true])_&]:absolute" +
|
|
9
|
+
" [.group[data-truncated=true]:is(:hover,[data-active=true])_&]:inset-x-0" +
|
|
10
|
+
" [.group[data-truncated=true]:is(:hover,[data-active=true])_&]:top-1/2" +
|
|
11
|
+
" [.group[data-truncated=true]:is(:hover,[data-active=true])_&]:-translate-y-1/2" +
|
|
12
|
+
" [.group[data-truncated=true]:is(:hover,[data-active=true])_&]:z-20" +
|
|
13
|
+
" [.group[data-truncated=true]:is(:hover,[data-active=true])_&]:whitespace-normal" +
|
|
14
|
+
" [.group[data-truncated=true]:is(:hover,[data-active=true])_&]:overflow-visible" +
|
|
15
|
+
" [.group[data-truncated=true]:is(:hover,[data-active=true])_&]:break-words" +
|
|
16
|
+
" [.group[data-truncated=true]:is(:hover,[data-active=true])_&]:rounded" +
|
|
17
|
+
" [.group[data-truncated=true]:is(:hover,[data-active=true])_&]:border" +
|
|
18
|
+
" [.group[data-truncated=true]:is(:hover,[data-active=true])_&]:border-secondary-200" +
|
|
19
|
+
" [.group[data-truncated=true]:is(:hover,[data-active=true])_&]:bg-white" +
|
|
20
|
+
" [.group[data-truncated=true]:is(:hover,[data-active=true])_&]:shadow-md" +
|
|
21
|
+
" [.group[data-truncated=true]:is(:hover,[data-active=true])_&]:p-2" +
|
|
22
|
+
" dark:[.group[data-truncated=true]:is(:hover,[data-active=true])_&]:border-primary-400" +
|
|
23
|
+
" dark:[.group[data-truncated=true]:is(:hover,[data-active=true])_&]:bg-iridium";
|