Skip to content

Commit

Permalink
Merge pull request #32 from pepabo/add-table-appearance-bg-and-border
Browse files Browse the repository at this point in the history
Tableコンポーネントで背景色とボーダーのパターンを追加します
  • Loading branch information
piyoppi authored Jul 10, 2024
2 parents 10ed364 + c46141d commit d0710e6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/stories-web/src/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ export interface Props extends HTMLProps {
children: ReactNode
density?: Density
size?: Extract<Size, 's' | 'm' | 'l'>
hasBackground?: boolean
hasGridBorder?: boolean
}

const Table: FC<Props> = (props: Props) => {
const {
children,
density,
size,
hasBackground,
hasGridBorder,
...rest
} = props;

Expand All @@ -27,6 +31,14 @@ const Table: FC<Props> = (props: Props) => {
classes.push(`-size-${size}`)
}

if (hasBackground) {
classes.push(`-has-background`)
}

if (hasGridBorder) {
classes.push(`-has-grid-border`)
}

return (
<table
className={classes.join(' ')}
Expand Down
6 changes: 6 additions & 0 deletions packages/stories-web/src/table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ Index.args = {
<td className="-align-right">9,000,000</td>
<td>スウェーデン語</td>
</tr>
<tr>
<td>日本</td>
<td>東京</td>
<td className="-align-right">120,000,000</td>
<td>日本語</td>
</tr>
</tbody>
),
density: 'normal',
Expand Down
31 changes: 31 additions & 0 deletions packages/table/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@
td {
border-bottom: adapter.get-table-border-size() solid adapter.get-border-color($brightness: light, $name: mid_emphasis);
}

@if map.get($option, hasBackground) == true {
@include -background-rule;
}

@if map.get($option, hasGirdBorder) == true {
@include -grid-border;
}

&.-has-background {
@include -background-rule;
}

&.-has-grid-border {
@include -grid-border;
}
}

@mixin -align() {
Expand All @@ -77,3 +93,18 @@
@include style;
}
}

@mixin -background-rule {
tr:nth-child(even) td {
background-color: adapter.get-surface-color(light, secondary);
}
tr:nth-child(odd) td {
background-color: adapter.get-surface-color(light, primary);
}
}

@mixin -grid-border {
th, td {
border: adapter.get-table-border-size() solid adapter.get-border-color($brightness: light, $name: mid_emphasis);
}
}
2 changes: 2 additions & 0 deletions packages/table/_variables.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
$default-option: (
has-background: false,
has-grid-border: false,
density: normal,
size: m,
);

0 comments on commit d0710e6

Please sign in to comment.