-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Remove no options panel when there are no options - Add a default placeholder - Improve TypeScript support
- Loading branch information
1 parent
cf125d3
commit 2c3000a
Showing
4 changed files
with
156 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import React from "react"; | ||
import { | ||
ClearIndicatorProps, | ||
components as selectComponents, | ||
ContainerProps, | ||
ControlProps, | ||
DropdownIndicatorProps, | ||
InputProps, | ||
MenuProps, | ||
MultiValueProps, | ||
} from "react-select"; | ||
import { components, GroupBase } from "react-select"; | ||
|
||
export const SelectControl = <Option, IsMulti extends boolean, Group extends GroupBase<Option>>( | ||
props: ControlProps<Option, IsMulti, Group> | ||
) => { | ||
// eslint-disable-next-line react/prop-types | ||
const { isFocused } = props; | ||
return ( | ||
<div data-testid="select-control"> | ||
<selectComponents.Control | ||
className={isFocused ? "nds-select--is-focused" : null} | ||
isFocused={isFocused} | ||
{...props} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export const SelectMultiValue = <Option, IsMulti extends boolean, Group extends GroupBase<Option>>( | ||
props: MultiValueProps<Option, IsMulti, Group> | ||
) => { | ||
return ( | ||
<div data-testid="select-multivalue"> | ||
<selectComponents.MultiValue {...props} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export const SelectClearIndicator = <Option, IsMulti extends boolean, Group extends GroupBase<Option>>( | ||
props: ClearIndicatorProps<Option, IsMulti, Group> | ||
) => { | ||
return ( | ||
<div data-testid="select-clear"> | ||
<selectComponents.ClearIndicator {...props} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export const SelectDropdownIndicator = <Option, IsMulti extends boolean, Group extends GroupBase<Option>>( | ||
props: DropdownIndicatorProps<Option, IsMulti, Group> | ||
) => { | ||
return ( | ||
<div data-testid="select-arrow"> | ||
<selectComponents.DropdownIndicator {...props} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export const SelectContainer = <Option, IsMulti extends boolean, Group extends GroupBase<Option>>( | ||
props: ContainerProps<Option, IsMulti, Group> | ||
) => { | ||
return ( | ||
<div data-testid="select-container"> | ||
<selectComponents.SelectContainer {...props} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export const SelectInput = <Option, IsMulti extends boolean, Group extends GroupBase<Option>>( | ||
props: InputProps<Option, IsMulti, Group> | ||
) => { | ||
return ( | ||
<div data-testid="select-input"> | ||
<selectComponents.Input {...props} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export const SelectMenu = <Option, IsMulti extends boolean, Group extends GroupBase<Option>>( | ||
props: MenuProps<Option, IsMulti, Group> | ||
) => { | ||
if (!props.selectProps.inputValue && props.options.length === 0) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div data-testid="select-dropdown"> | ||
<components.Menu {...props} /> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters