Initial commit

This commit is contained in:
2025-03-07 19:22:02 +01:00
commit 4a98255d83
55743 changed files with 5280367 additions and 0 deletions
@@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "useComboboxFilter", {
enumerable: true,
get: function() {
return useComboboxFilter;
}
});
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
const _Option = require("../Option");
function defaultFilter(optionText, query) {
if (query === '') {
return true;
}
return optionText.toLowerCase().includes(query.toLowerCase());
}
function defaultToString(option) {
return typeof option === 'string' ? option : option.value;
}
function useComboboxFilter(query, options, config) {
const { filter = defaultFilter, noOptionsMessage = "We couldn't find any matches.", optionToReactKey = defaultToString, optionToText = defaultToString, renderOption = (option)=>{
if (typeof option === 'string') {
return /*#__PURE__*/ _react.createElement(_Option.Option, {
key: option
}, option);
}
return /*#__PURE__*/ _react.createElement(_Option.Option, {
...option,
key: optionToReactKey(option),
text: optionToText(option),
value: option.value
}, option.children);
} } = config;
const filteredOptions = _react.useMemo(()=>{
const searchValue = query.trim();
return options.filter((option)=>filter(optionToText(option), searchValue));
}, [
options,
optionToText,
filter,
query
]);
if (filteredOptions.length === 0) {
return [
/*#__PURE__*/ _react.createElement(_Option.Option, {
"aria-disabled": "true",
key: "no-results",
text: ""
}, noOptionsMessage)
];
}
return filteredOptions.map((option)=>renderOption(option));
}
@@ -0,0 +1 @@
{"version":3,"sources":["../src/hooks/useComboboxFilter.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Option } from '../Option';\n\ntype UseComboboxFilterConfig<T extends { children: React.ReactNode; value: string } | string> = {\n /** Provides a custom filter for the option. */\n filter?: (optionText: string, query: string) => boolean;\n\n /** Provides a custom message to display when there are no options. */\n noOptionsMessage?: React.ReactNode;\n\n /** Provides a way to map an option object to a React key. By default, \"value\" is used. */\n optionToReactKey?: (option: T) => string;\n\n /** Provides a way to map an option object to a text used for search. By default, \"value\" is used. */\n optionToText?: (option: T) => string;\n\n /** Provides a custom render for the option. */\n renderOption?: (option: T) => JSX.Element;\n};\n\nfunction defaultFilter(optionText: string, query: string) {\n if (query === '') {\n return true;\n }\n\n return optionText.toLowerCase().includes(query.toLowerCase());\n}\n\nfunction defaultToString(option: string | { value: string }) {\n return typeof option === 'string' ? option : option.value;\n}\n\n/**\n * @internal\n */\nexport function useComboboxFilter<T extends { children: React.ReactNode; value: string } | string>(\n query: string,\n options: T[],\n config: UseComboboxFilterConfig<T>,\n) {\n const {\n filter = defaultFilter,\n noOptionsMessage = \"We couldn't find any matches.\",\n optionToReactKey = defaultToString,\n optionToText = defaultToString,\n\n renderOption = (option: T) => {\n if (typeof option === 'string') {\n return <Option key={option}>{option}</Option>;\n }\n\n return (\n <Option {...option} key={optionToReactKey(option)} text={optionToText(option)} value={option.value}>\n {option.children}\n </Option>\n );\n },\n } = config;\n\n const filteredOptions = React.useMemo(() => {\n const searchValue = query.trim();\n\n return options.filter(option => filter(optionToText(option), searchValue));\n }, [options, optionToText, filter, query]);\n\n if (filteredOptions.length === 0) {\n return [\n <Option aria-disabled=\"true\" key=\"no-results\" text=\"\">\n {noOptionsMessage}\n </Option>,\n ];\n }\n\n return filteredOptions.map(option => renderOption(option));\n}\n"],"names":["useComboboxFilter","defaultFilter","optionText","query","toLowerCase","includes","defaultToString","option","value","options","config","filter","noOptionsMessage","optionToReactKey","optionToText","renderOption","React","createElement","Option","key","text","children","filteredOptions","useMemo","searchValue","trim","length","aria-disabled","map"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BAmCgBA;;;eAAAA;;;;iEAnCO;wBACA;AAmBvB,SAASC,cAAcC,UAAkB,EAAEC,KAAa;IACtD,IAAIA,UAAU,IAAI;QAChB,OAAO;IACT;IAEA,OAAOD,WAAWE,WAAW,GAAGC,QAAQ,CAACF,MAAMC,WAAW;AAC5D;AAEA,SAASE,gB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