Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨(react) add async mode to Select #305

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
457d922
✨(react) introduce mono async searchable select
daproclaima Mar 12, 2024
cd38f69
⚡️(react) prevent unecessary async options fetching
daproclaima Apr 25, 2024
c795bd5
✅(react) update test for select with async options fetching
daproclaima Apr 26, 2024
c876a16
✨(react) add use of loader in mono searchable select
daproclaima Apr 30, 2024
8c576ba
✅(react) add test for searchable mono select
daproclaima Apr 30, 2024
bb2c096
💬(react) add select loader translations
daproclaima Jun 14, 2024
f573509
🔧(vitest) add workspace configuration
daproclaima Jun 19, 2024
5d9dee9
♻️(react) improve select mono searchable
daproclaima Jun 19, 2024
7d25e30
♻️(react) gather options fetching code in mono select
daproclaima Jun 20, 2024
6be1825
✅(react) test controlled Select mono searchable with fetched options
daproclaima Jun 20, 2024
193b0fe
📝(react) add story for Select mono
daproclaima Jun 21, 2024
104b794
📝(react) update documentation of mono select
daproclaima Jun 24, 2024
0dfb7b7
💄(react) move loader for select mono searchable
daproclaima Jun 27, 2024
19a0ca0
🐛(react) fix options fetching in select mono searchable
daproclaima Jun 27, 2024
ab25244
🐛(react) fix options reset for select mono searchable
daproclaima Jun 27, 2024
1965f80
🐛(react) fix select mono searchable menu toggle
daproclaima Jun 27, 2024
6f212af
⏪️(react) revert select mono searchable menu toggle change
daproclaima Jun 27, 2024
f883441
⏪️(react) cancel options reset for select mono searchable
daproclaima Jun 27, 2024
8051ba5
🐛(react) fix options reset for select mono searchable
daproclaima Jun 27, 2024
0fd628f
📝(react) update stories for mono select
daproclaima Jun 27, 2024
f744390
🐛(react) select mono searchable work with loading state
daproclaima Jul 22, 2024
00d50dd
🚸(react) change select mono arrow button
daproclaima Jul 22, 2024
6fd14cb
✨(react) add options fetching to controllable select mono searchable
daproclaima Jul 25, 2024
0f780aa
🐛(react) update mono select options fetching
daproclaima Jul 31, 2024
3a1607b
📝(react) update stories for mono select
daproclaima Jul 31, 2024
ab61478
🎨(react) improve select mono-common code
daproclaima Sep 23, 2024
13e89dc
🚨(react) fix select mono stories
daproclaima Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dist
*.njsproj
*.sln
*.sw?
*.tool-versions

vite.config.ts.timestamp-*
env.d
Expand Down
8 changes: 8 additions & 0 deletions packages/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @openfun/cunningham-react

## 2.10.0

### Minor Changes

- 0b45f51: add async option fetching mode to select mono

## 2.9.4

### Patch Changes
Expand Down Expand Up @@ -425,6 +431,8 @@
- 4ebbf16: Add component's tokens handling

[unreleased]: https://github.com/openfun/cunningham/compare/@openfun/[email protected]
[2.10.0]: https://github.com/openfun/cunningham/compare/@openfun/[email protected]...@openfun/[email protected]
[2.9.4]: https://github.com/openfun/cunningham/compare/@openfun/[email protected]...@openfun/[email protected]
[2.9.3]: https://github.com/openfun/cunningham/compare/@openfun/[email protected]...@openfun/[email protected]
[2.9.2]: https://github.com/openfun/cunningham/compare/@openfun/[email protected]...@openfun/[email protected]
[2.9.1]: https://github.com/openfun/cunningham/compare/@openfun/[email protected]...@openfun/[email protected]
Expand Down
13 changes: 13 additions & 0 deletions packages/react/src/components/Forms/Select/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
.c__select {
position: relative;

&__loader {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: right;
cursor: wait;
}

&__wrapper {
border-radius: var(--c--components--forms-select--border-radius);
border-width: var(--c--components--forms-select--border-width);
Expand Down Expand Up @@ -99,6 +108,10 @@
}
&__open {
color: var(--c--theme--colors--greyscale-900);

&--hidden {
display: none;
}
}
}
}
Expand Down
17 changes: 15 additions & 2 deletions packages/react/src/components/Forms/Select/index.tsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should reword the commit eaf2953488a16d1cfa9722c071786afb53f345f2

Actually, the gitmoji used mention work in progress

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ export type OptionWithoutRender = Omit<BaseOption, "value" | "render"> & {

export type Option = OptionWithoutRender | OptionWithRender;

export type ContextCallbackFetchOptions = {
search?: string | number;
};

export type CallbackFetchOptions = (
context: ContextCallbackFetchOptions,
) => Promise<Option[]>;

export interface SelectHandle {
blur: () => void;
}
Expand All @@ -31,7 +39,7 @@ export type SelectProps = PropsWithChildren &
FieldProps & {
label: string;
hideLabel?: boolean;
options: Option[];
options: Option[] | CallbackFetchOptions;
searchable?: boolean;
name?: string;
defaultValue?: string | number | string[];
Expand All @@ -45,6 +53,7 @@ export type SelectProps = PropsWithChildren &
disabled?: boolean;
clearable?: boolean;
multi?: boolean;
isLoading?: boolean;
showLabelWhenSelected?: boolean;
monoline?: boolean;
selectedItemsStyle?: "pills" | "text";
Expand All @@ -63,6 +72,10 @@ export const Select = forwardRef<SelectHandle, SelectProps>((props, ref) => {
return props.multi ? (
<SelectMulti {...props} ref={ref} />
) : (
<SelectMono {...props} ref={ref} />
<SelectMono
{...props}
ref={ref}
value={Array.isArray(props.value) ? undefined : props.value}
/>
);
});
15 changes: 13 additions & 2 deletions packages/react/src/components/Forms/Select/mono-common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Button } from ":/components/Button";
import { Option, SelectProps } from ":/components/Forms/Select";
import { isOptionWithRender } from ":/components/Forms/Select/utils";
import { SelectMenu } from ":/components/Forms/Select/select-menu";
import { UpdateArrayOptionsType } from ":/components/Forms/Select/mono-searchable";

export function getOptionsFilter(inputValue?: string) {
return (option: Option) => {
Expand Down Expand Up @@ -53,6 +54,7 @@ export interface SubProps extends SelectProps {
export interface SelectAuxProps extends SubProps {
options: Option[];
labelAsPlaceholder: boolean;
updateArrayOptions?: UpdateArrayOptionsType;
downshiftReturn: {
isOpen: boolean;
wrapperProps?: HTMLAttributes<HTMLDivElement>;
Expand Down Expand Up @@ -84,12 +86,16 @@ export const SelectMonoAux = ({
disabled,
clearable = true,
onBlur,
updateArrayOptions,
...props
}: SelectAuxProps) => {
const { t } = useCunningham();
const labelProps = downshiftReturn.getLabelProps();
const ref = useRef<HTMLDivElement>(null);

const isToReset =
!props.isLoading && clearable && !disabled && downshiftReturn.selectedItem;

return (
<>
<Field state={state} {...props}>
Expand Down Expand Up @@ -135,7 +141,7 @@ export const SelectMonoAux = ({
<div className="c__select__inner">
<div className="c__select__inner__value">{children}</div>
<div className="c__select__inner__actions">
{clearable && !disabled && downshiftReturn.selectedItem && (
{isToReset && (
<>
<Button
color="tertiary-text"
Expand All @@ -146,6 +152,9 @@ export const SelectMonoAux = ({
className="c__select__inner__actions__clear"
onClick={(e) => {
downshiftReturn.selectItem(null);
if (typeof updateArrayOptions === "function") {
updateArrayOptions(undefined);
}
e.stopPropagation();
}}
icon={<span className="material-icons">close</span>}
Expand All @@ -158,7 +167,9 @@ export const SelectMonoAux = ({
<Button
color="tertiary-text"
size="nano"
className="c__select__inner__actions__open"
className={`c__select__inner__actions__open
c__select__inner__actions__open${props.isLoading ? "--hidden" : ""}
`}
icon={
<span
className={classNames("material-icons", {
Expand Down
Loading