From feda64b09eb739debd3acb0029e01afe487fbda1 Mon Sep 17 00:00:00 2001 From: Klink <85062+dogmar@users.noreply.github.com> Date: Fri, 14 Apr 2023 16:06:01 -0700 Subject: [PATCH] fix: Fix styles (#455) --- src/components/Breadcrumbs.tsx | 2 - src/components/Input.tsx | 85 +++++++++++++++++++++++----------- src/components/Select.tsx | 29 ++++++------ src/stories/Input.stories.tsx | 3 ++ 4 files changed, 73 insertions(+), 46 deletions(-) diff --git a/src/components/Breadcrumbs.tsx b/src/components/Breadcrumbs.tsx index 9aab9483..9aea24d9 100644 --- a/src/components/Breadcrumbs.tsx +++ b/src/components/Breadcrumbs.tsx @@ -199,8 +199,6 @@ function CrumbListRef( breadcrumbs.length ) - console.log('ariaOnly', ariaOnly, visuallyHiddenProps) - return (
    ({ + display: 'flex', + alignItems: 'center', alignSelf: 'stretch', - paddingHorizontal: 'small', - backgroundColor: 'fill-two', + paddingLeft: theme.spacing.small, + paddingRight: theme.spacing.small, + backgroundColor: theme.colors['fill-two'], +})) + +const startEndStyles = { + alignSelf: 'stretch', + display: 'flex', + gap: 'small', + marginRight: 0, + marginLeft: 0, + paddingRight: 0, + paddingLeft: 0, } +const InputTitleContent = styled(TitleContent)((_) => ({ + alignSelf: 'stretch', +})) + const Input = forwardRef( ( { startIcon, endIcon, suffix, prefix, titleContent, ...props }: InputProps, ref ) => { let themeExtension: any = {} - const theme = useTheme() const parentFillLevel = useFillLevel() const size = (props as any).large ? 'large' @@ -32,35 +48,26 @@ const Input = forwardRef( ? 'small' : 'medium' - const titleContentIconStyle = useMemo( - () => ({ - ...titleContentStyles({ theme, parentFillLevel, size }), - alignSelf: 'stretch', - }), - [parentFillLevel, theme, size] - ) - if (suffix) { themeExtension = mergeTheme(themeExtension, { Input: { Root: [{ paddingRight: 0 }], - EndIcon: [prefixSuffixIconStyle], - }, - }) - } - if (prefix) { - themeExtension = mergeTheme(themeExtension, { - Input: { - Root: [{ paddingLeft: 0 }], - StartIcon: [prefixSuffixIconStyle], + EndIcon: [{ ...startEndStyles, ...{ paddingLeft: 'xsmall' } }], }, }) } - if (titleContent) { + if (prefix || titleContent) { themeExtension = mergeTheme(themeExtension, { Input: { Root: [{ paddingLeft: 0 }], - StartIcon: [titleContentIconStyle], + StartIcon: [ + { + ...startEndStyles, + ...{ + paddingRight: titleContent && !startIcon ? 'small' : 'xsmall', + }, + }, + ], }, }) } @@ -69,8 +76,30 @@ const Input = forwardRef( + {endIcon} + {suffix && {suffix}} + + ) : undefined + } + startIcon={ + startIcon || prefix || titleContent ? ( + <> + {(titleContent && ( + + {titleContent} + + )) || + (prefix && {prefix})} + {startIcon} + + ) : undefined + } {...props} /> diff --git a/src/components/Select.tsx b/src/components/Select.tsx index ecc2e9a5..7ff79008 100644 --- a/src/components/Select.tsx +++ b/src/components/Select.tsx @@ -95,15 +95,10 @@ function Trigger({ buttonElt, isOpen, ...props }: TriggerProps) { }) } -export const titleContentStyles = ({ - theme, - parentFillLevel, - size = 'medium', -}: { - theme: any - parentFillLevel: FillLevel - size?: Size -}) => { +export const TitleContent = styled.div<{ + $size: Size + $parentFillLevel: FillLevel +}>(({ theme, $size: size, $parentFillLevel: parentFillLevel }) => { const hPad = theme.spacing.small const vPad = size === 'small' ? 5 : 9 @@ -122,7 +117,7 @@ export const titleContentStyles = ({ paddingLeft: hPad, paddingRight: hPad, } -} +}) const SelectButtonInner = styled.div<{ $isOpen: boolean @@ -145,11 +140,6 @@ const SelectButtonInner = styled.div<{ color: theme.colors['text-light'], border: theme.borders.input, borderRadius: theme.borderRadiuses.medium, - '.titleContent': titleContentStyles({ - theme, - size, - parentFillLevel, - }), '.content': { alignItems: 'center', display: 'flex', @@ -212,7 +202,14 @@ const SelectButton = forwardRef< $parentFillLevel={parentFillLevel} {...props} > - {titleContent &&
    {titleContent}
    } + {titleContent && ( + + {titleContent} + + )}
    {leftContent &&
    {leftContent}
    }
    {children}
    diff --git a/src/stories/Input.stories.tsx b/src/stories/Input.stories.tsx index 1e22cf43..254eb022 100644 --- a/src/stories/Input.stories.tsx +++ b/src/stories/Input.stories.tsx @@ -3,6 +3,7 @@ import { Div, Flex } from 'honorable' import MagnifyingGlassIcon from '../components/icons/MagnifyingGlassIcon' import BrowseAppsIcon from '../components/icons/BrowseAppsIcon' import CaretDownIcon from '../components/icons/CaretDownIcon' +import SearchIcon from '../components/icons/SearchIcon' import Input from '../components/Input' export default { @@ -104,10 +105,12 @@ Multiline.args = { export const TitleContent = CustomInputTemplate.bind({}) TitleContent.args = { + startIcon: , titleContent: ( <> Marketplace ), + placeholder: 'Search the marketplace', }