@spark-ui/components
Version:
Spark (Leboncoin design system) components.
168 lines (154 loc) • 5.17 kB
TypeScript
import * as react_jsx_runtime from 'react/jsx-runtime';
import { ReactElement, Dispatch, SetStateAction, PropsWithChildren, ReactNode, Ref, ComponentPropsWithRef } from 'react';
interface SelectItem {
disabled: boolean;
value: string;
text: string;
}
type ItemsMap = Map<string, SelectItem>;
interface SelectContextState {
itemsMap: ItemsMap;
disabled: boolean;
readOnly: boolean;
state?: 'error' | 'alert' | 'success';
itemsComponent: ReactElement | undefined;
selectedItem: SelectItem | undefined;
setValue: (value: string) => void;
isControlled: boolean;
onValueChange?: (value: string) => void;
ariaLabel: string | undefined;
setAriaLabel: Dispatch<SetStateAction<string | undefined>>;
fieldId: string;
fieldLabelId: string | undefined;
name: string | undefined;
required: boolean;
placeholder: string | undefined;
setPlaceholder: Dispatch<SetStateAction<string | undefined>>;
}
type SelectContextProps = PropsWithChildren<{
/**
* Use `state` prop to assign a specific state to the select, choosing from: `error`, `alert` and `success`. By doing so, the outline styles will be updated.
*/
state?: 'error' | 'alert' | 'success';
/**
* When true, prevents the user from interacting with the select.
*/
disabled?: boolean;
/**
* Sets the select as interactive or not.
*/
readOnly?: boolean;
/**
* The value of the select when initially rendered. Use when you do not need to control the state of the select.
*/
defaultValue?: string;
/**
* The controlled value of the select. Should be used in conjunction with `onValueChange`.
*/
value?: string;
/**
* Event handler called when the value changes.
*/
onValueChange?: (value: string) => void;
itemsComponent: ReactElement | undefined;
/**
* This attribute is used to specify the name of the control.
* If wrapped with a FormField with a name, will be inherited from it.
*/
name?: string;
/**
* A Boolean attribute indicating that an option with a non-empty string value must be selected.
*/
required?: boolean;
}>;
declare const SelectProvider: ({ children, defaultValue, value: valueProp, onValueChange, disabled: disabledProp, readOnly: readOnlyProp, state: stateProp, itemsComponent, name: nameProp, required: requiredProp, }: SelectContextProps) => react_jsx_runtime.JSX.Element;
declare const useSelectContext: () => SelectContextState;
type SelectProps = Omit<SelectContextProps, 'itemsComponent'>;
declare const Select$1: {
({ children, ...props }: SelectProps): react_jsx_runtime.JSX.Element;
displayName: string;
};
interface GroupProps {
children: ReactNode;
className?: string;
ref?: Ref<HTMLOptGroupElement>;
}
declare const Group: {
({ children, ref: forwardedRef, ...props }: GroupProps): react_jsx_runtime.JSX.Element;
displayName: string;
};
interface ItemProps {
disabled?: boolean;
value: string;
children: string;
ref?: Ref<HTMLOptionElement>;
}
declare const Item: {
({ disabled, value, children, ref: forwardedRef }: ItemProps): react_jsx_runtime.JSX.Element;
displayName: string;
};
declare const Items: {
({ children, className, ref, ...rest }: PropsWithChildren<ComponentPropsWithRef<"select">>): react_jsx_runtime.JSX.Element;
displayName: string;
};
interface LabelProps {
children: string;
}
declare const Label: {
({ children }: LabelProps): null;
displayName: string;
};
declare const LeadingIcon: {
({ children }: {
children: ReactElement;
}): react_jsx_runtime.JSX.Element;
displayName: string;
};
interface PlaceholderProps {
disabled?: boolean;
children: string;
ref?: Ref<HTMLOptionElement>;
}
declare const Placeholder: {
({ disabled, children, ref: forwardedRef, }: PlaceholderProps): react_jsx_runtime.JSX.Element;
displayName: string;
};
interface TriggerProps {
'aria-label'?: string;
children: ReactNode;
className?: string;
ref?: Ref<HTMLDivElement>;
}
/**
* This trigger acts as a fake button for the `select` tag.
* It is not interactive.
*/
declare const Trigger: {
({ "aria-label": ariaLabel, children, className, ref: forwardedRef, }: TriggerProps): react_jsx_runtime.JSX.Element;
displayName: string;
};
interface ValueProps {
children?: ReactNode;
className?: string;
/**
* Optional placeholder value for the trigger.
* If not specified, the value inside `Select.Placeholder` item will be used.
*/
placeholder?: string;
ref?: Ref<HTMLSpanElement>;
}
declare const Value: {
({ children, className, placeholder: customPlaceholder, ref: forwardedRef, }: ValueProps): react_jsx_runtime.JSX.Element;
displayName: string;
};
declare const Select: typeof Select$1 & {
Group: typeof Group;
Item: typeof Item;
Items: typeof Items;
Placeholder: typeof Placeholder;
Label: typeof Label;
Trigger: typeof Trigger;
Value: typeof Value;
LeadingIcon: typeof LeadingIcon;
};
export { Select, SelectProvider, useSelectContext };