diff --git a/src/AsyncSelect/AsyncSelect.story.tsx b/src/AsyncSelect/AsyncSelect.story.tsx index 41237508b..bd4ef9733 100644 --- a/src/AsyncSelect/AsyncSelect.story.tsx +++ b/src/AsyncSelect/AsyncSelect.story.tsx @@ -22,10 +22,6 @@ export const Default = () => ( /> ); -Default.story = { - name: "default", -}; - export const WithDefaultOptions = () => ( { ); }; -Controlled.story = { - name: "controlled", -}; +export const WithIcon = () => ( + +); diff --git a/src/AsyncSelect/AsyncSelect.tsx b/src/AsyncSelect/AsyncSelect.tsx index 9d43d6f8f..43e83afd7 100644 --- a/src/AsyncSelect/AsyncSelect.tsx +++ b/src/AsyncSelect/AsyncSelect.tsx @@ -1,4 +1,5 @@ import React, { forwardRef, ReactNode, MutableRefObject } from "react"; +import { IconName } from "@nulogy/icons"; import Select from "react-select/base"; import AsyncReactSelect from "react-select/async"; import { AsyncProps } from "react-select/async"; @@ -36,6 +37,7 @@ type AsyncCustomProps["isMulti"]; maxHeight?: string; defaultValue?: AsyncProps["defaultInputValue"]; + iconLeft?: IconName | "loading"; }; export type AsyncSelectProps> = Omit< @@ -80,6 +82,7 @@ const AsyncSelect = forwardRef( loadOptions, isClearable, variant, + iconLeft, ...props }: AsyncSelectProps, ref: @@ -106,6 +109,7 @@ const AsyncSelect = forwardRef( defaultInputValue={defaultValue} placeholder={placeholder || t("start typing")} styles={customStyles({ + hasIcon: Boolean(iconLeft), theme, error, maxHeight, @@ -135,7 +139,11 @@ const AsyncSelect = forwardRef( {props.children} ), - Control: SelectControl, + Control: (props) => ( + + {props.children} + + ), MultiValue: SelectMultiValue, ClearIndicator: SelectClearIndicator, DropdownIndicator: SelectDropdownIndicator, diff --git a/src/AsyncSelect/AsyncSelectComponents.tsx b/src/AsyncSelect/AsyncSelectComponents.tsx index 05f3dcf68..120e20813 100644 --- a/src/AsyncSelect/AsyncSelectComponents.tsx +++ b/src/AsyncSelect/AsyncSelectComponents.tsx @@ -14,12 +14,17 @@ import type { OptionProps } from "react-windowed-select"; import { useComponentVariant } from "../NDSProvider/ComponentVariantContext"; import type { ComponentVariant } from "../NDSProvider/ComponentVariantContext"; import { StyledOption } from "../Select/SelectOption"; +import { IconName } from "@nulogy/icons"; +import { InputIcon } from "../Icon/Icon"; -export const SelectControl = >( - props: ControlProps -) => { - // eslint-disable-next-line react/prop-types - const { isFocused } = props; +export const SelectControl = >({ + iconLeft, + isFocused, + children, + ...props +}: ControlProps & { + iconLeft?: IconName | "loading"; +}) => { return (
- {props.children} + {iconLeft && } + {children}
); diff --git a/src/Icon/Icon.tsx b/src/Icon/Icon.tsx index 47fe5e831..bb0304d02 100644 --- a/src/Icon/Icon.tsx +++ b/src/Icon/Icon.tsx @@ -1,6 +1,6 @@ import React from "react"; import styled, { useTheme } from "styled-components"; -import { space, SpaceProps } from "styled-system"; +import { position, PositionProps, space, SpaceProps } from "styled-system"; import icons from "@nulogy/icons"; import { IconName } from "@nulogy/icons"; import LoadingIcon from "./LoadingIcon"; @@ -101,4 +101,15 @@ export function InlineIcon(props: IconProps) { ); } +export const InputIcon = styled(Icon)( + ({ theme }) => ({ + position: "absolute", + color: theme.colors.midGrey, + bottom: "50%", + transform: "translateY(50%)", + pointerEvents: "none", + }), + position +); + export default Icon; diff --git a/src/Input/InputField.tsx b/src/Input/InputField.tsx index 652a301a7..62c67f609 100644 --- a/src/Input/InputField.tsx +++ b/src/Input/InputField.tsx @@ -11,6 +11,7 @@ import type { DefaultNDSThemeType } from "../theme"; import { ComponentVariant, useComponentVariant } from "../NDSProvider/ComponentVariantContext"; import Prefix from "./Prefix"; import Suffix from "./Suffix"; +import { InputIcon } from "../Icon/Icon"; type NativeInputProps = Omit, "size" | "height" | "width">; @@ -67,7 +68,7 @@ export const InputField = forwardRef( - {iconLeft && } + {iconLeft && } ( inputWidth={inputWidth} {...props} /> - {iconRight && } + {iconRight && } @@ -143,17 +144,6 @@ const StyledInput = styled.input( space ); -const StyledInputIcon = styled(Icon)<{ variant: ComponentVariant } & PositionProps>( - ({ theme }) => ({ - position: "absolute", - color: theme.colors.midGrey, - bottom: "50%", - transform: "translateY(50%)", - pointerEvents: "none", - }), - position -); - const cssForState = ({ disabled, error, diff --git a/src/Select/customReactSelectStyles.tsx b/src/Select/customReactSelectStyles.tsx index 885acaa59..032897a26 100644 --- a/src/Select/customReactSelectStyles.tsx +++ b/src/Select/customReactSelectStyles.tsx @@ -96,6 +96,7 @@ const customStyles: { @@ -169,6 +170,9 @@ const customStyles: ({ ...provided,