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

fix: SearchInputのwrapperであるlabel要素に対してwidthを指定する #4961

Merged
merged 3 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Meta, StoryObj } from '@storybook/react'
import React from 'react'
import styled, { css } from 'styled-components'

import { Stack } from '../../Layout'
import { Button } from '../../Button'
import { Cluster, Stack } from '../../Layout'

import { SearchInput } from './SearchInput'

Expand Down Expand Up @@ -39,6 +40,42 @@ export const Default: Story = {
decorators={{ iconAlt: (txt) => `search.(${txt})` }}
/>
</div>
<div>
<p>width: 300px in Cluster</p>
<StyledCluster>
<SearchInput
name="default"
width={300}
tooltipMessage="氏名、ヨミガナ、社員番号で検索できます。スペース区切りでAND検索ができます。"
decorators={{ iconAlt: (txt) => `search.(${txt})` }}
/>
<Button>検索</Button>
</StyledCluster>
</div>
<div>
<p>width: 100% in Cluster</p>
<StyledCluster justify="space-between">
<SearchInput
name="default"
width="100%"
tooltipMessage="氏名、ヨミガナ、社員番号で検索できます。スペース区切りでAND検索ができます。"
decorators={{ iconAlt: (txt) => `search.(${txt})` }}
/>
<Button>検索</Button>
</StyledCluster>
</div>
<div>
<p>width: 50% in Cluster</p>
<StyledCluster>
<SearchInput
name="default"
width="50%"
tooltipMessage="氏名、ヨミガナ、社員番号で検索できます。スペース区切りでAND検索ができます。"
decorators={{ iconAlt: (txt) => `search.(${txt})` }}
/>
<Button>検索</Button>
</StyledCluster>
</div>
</StyledStack>
),
}
Expand All @@ -48,3 +85,7 @@ const StyledStack = styled(Stack)`
padding: ${space(2)};
`}
`

const StyledCluster = styled(Cluster)`
flex-wrap: nowrap;
`
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,36 @@ type Props = Omit<ComponentProps<typeof InputWithTooltip>, 'tooltipMessage' | 'p

const ICON_ALT = '検索'

export const SearchInput = forwardRef<HTMLInputElement, Props>(({ decorators, ...props }, ref) => {
const iconAlt = useMemo(() => decorators?.iconAlt?.(ICON_ALT) || ICON_ALT, [decorators])

return (
<label>
<InputWithTooltip
{...props}
ref={ref}
prefix={<FaSearchIcon alt={iconAlt} color="TEXT_GREY" />}
/>
</label>
)
})
export const SearchInput = forwardRef<HTMLInputElement, Props>(
({ decorators, width, ...props }, ref) => {
const iconAlt = useMemo(() => decorators?.iconAlt?.(ICON_ALT) || ICON_ALT, [decorators])
const styles = useMemo(() => {
const widthStyle = typeof width === 'number' ? `${width}px` : width

if (!widthStyle) {
return {
label: undefined,
input: undefined,
}
}

return {
label: {
width: widthStyle,
},
input: '100%',
}
}, [width])

return (
<label style={styles.label}>
<InputWithTooltip
{...props}
ref={ref}
width={styles.input}
prefix={<FaSearchIcon alt={iconAlt} color="TEXT_GREY" />}
/>
</label>
)
},
)