Skip to content

Commit

Permalink
Merge pull request #121 from 8845musign/inline-box-and-flex
Browse files Browse the repository at this point in the history
Add Inline prop to box and flex component
  • Loading branch information
takanorip authored Jul 17, 2024
2 parents 4e19e3b + 026d147 commit 2c53526
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/components/Box/Box.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@
.box.textNoWrap {
white-space: nowrap;
}

.box.inline {
display: inline-block;
}
7 changes: 7 additions & 0 deletions src/components/Box/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ type BaseProps = {
* 領域が狭い場合でも、テキストを折り返えさない
*/
textNoWrap?: boolean;
/**
* inline-blockとして扱う
* @default false
*/
inline?: boolean;
} & PaddingProps &
MarginProps &
RadiusProp &
Expand Down Expand Up @@ -185,6 +190,7 @@ export const Box: FC<PropsWithoutText | PropsWithTextBody | PropsWithTextNote> =
backgroundColor,
border,
width,
inline = false,
textType,
textSize,
textLeading,
Expand All @@ -209,6 +215,7 @@ export const Box: FC<PropsWithoutText | PropsWithTextBody | PropsWithTextNote> =
backgroundColor && styles[`backgroundColor${capitalize(backgroundColor)}`],
border && styles[`border${capitalize(border)}`],
width && styles.widthFull,
inline && styles.inline,
textBold && styles.textBold,
textBold === false && styles.textNormal,
textAlign && styles[`text${capitalize(textAlign)}`],
Expand Down
4 changes: 4 additions & 0 deletions src/components/Flex/Flex.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
.flex.widthFull {
width: 100%;
}

.flex.inline {
display: inline-flex;
}
13 changes: 12 additions & 1 deletion src/components/Flex/Flex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ type Props = {
* デフォルト<Flex>は横幅いっぱいを専有する。しかし例えば、フレックスコンテナの子要素として配置した場合、横幅が自身の子に合わせて小さくなる。これが不都合の場合に100%とする事が可能
*/
width?: 'full';
/**
* inline-flexとして扱う
* @default false
*/
inline?: boolean;
} & MarginProps &
PaddingProps &
CustomDataAttributeProps;
Expand All @@ -64,6 +69,7 @@ export const Flex: FC<PropsWithChildren<Props>> = ({
spacing,
height,
width,
inline,
p,
px,
py,
Expand Down Expand Up @@ -91,7 +97,12 @@ export const Flex: FC<PropsWithChildren<Props>> = ({

return createElement(
{
className: clsx(styles.flex, height === 'full' && styles.heightFull, width === 'full' && styles.widthFull),
className: clsx(
styles.flex,
height === 'full' && styles.heightFull,
width === 'full' && styles.widthFull,
inline && styles.inline,
),
style: {
'--flex-direction': direction,
'--align-items': alignItems,
Expand Down
20 changes: 20 additions & 0 deletions src/stories/Box.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,23 @@ export const TextWrap: Story = {
...defaultArgs,
},
};

export const Inline: Story = {
render: (args) => (
<p>
文章文章文章
<Box {...args} inline>
インライン
</Box>
文章文章文章
</p>
),
args: {
...defaultArgs,
as: 'span',
backgroundColor: 'primary',
inline: true,
p: 'xs',
m: 'sm',
},
};
20 changes: 20 additions & 0 deletions src/stories/Flex.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,23 @@ export const WithFlexItem: Story = {
</div>
),
};

export const Inline: Story = {
render: () => (
<p>
文章文章文章文章文章文章
<Flex as="span" spacing="md" inline>
<Box as="span" inline backgroundColor="primary" p="xs" radius="md">
Item
</Box>
<Box as="span" inline backgroundColor="primary" p="xs" radius="md">
Item
</Box>
<Box as="span" inline backgroundColor="primary" p="xs" radius="md">
Item
</Box>
</Flex>
文章
</p>
),
};

0 comments on commit 2c53526

Please sign in to comment.