-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from pepabo/inhouse-alert
アプリケーションのステータスを表示する目的として利用されるAlertを追加
- Loading branch information
Showing
13 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Inhouse Alert | ||
|
||
## Usage | ||
|
||
### Installation | ||
|
||
```bash | ||
$ npm install @pepabo-inhouse/alert | ||
|
||
# or | ||
|
||
$ yarn add @pepabo-inhouse/alert | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@forward "./mixins" show style, export; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
@use "sass:map"; | ||
@use "sass:list"; | ||
@use "@pepabo-inhouse/adapter/functions" as adapter; | ||
@use "./variables"; | ||
|
||
@mixin style($options: variables.$default-options) { | ||
display: flex; | ||
$options: map.merge(variables.$default-options, $options); | ||
padding: adapter.get-spacing-size(map.get($options, size)); | ||
border-radius: adapter.get-radius-size(map.get($options, size)); | ||
box-shadow: adapter.get-elevation-box-shadow(1); | ||
font-size: adapter.get-font-size(map.get($options, size)); | ||
line-height: adapter.get-line-height($level: map.get($options, size), $density: normal); | ||
|
||
._leading { | ||
padding-right: adapter.get-spacing-size(s); | ||
} | ||
|
||
._title { | ||
margin-top: 0; | ||
} | ||
|
||
@include -state-style(map-get($options, color)); | ||
@include -size-style(map-get($options, size)); | ||
|
||
&.-color-informative { | ||
@include -state-style(informative); | ||
} | ||
|
||
&.-color-positive { | ||
@include -state-style(positive); | ||
} | ||
|
||
&.-color-negative { | ||
@include -state-style(negative); | ||
} | ||
|
||
&.-color-notice { | ||
@include -state-style(notice); | ||
} | ||
|
||
@each $size in 's', 'm', 'l' { | ||
&.-size-#{$size} { | ||
@include -size-style($size); | ||
} | ||
} | ||
} | ||
|
||
@mixin -state-style($state) { | ||
background-color: adapter.get-semantic-color($state, 100); | ||
color: adapter.get-semantic-color($state, 800); | ||
|
||
._leading:after { | ||
content: map-get(variables.$icon-map, $state); | ||
} | ||
} | ||
|
||
@mixin -size-style($size) { | ||
font-size: adapter.get-font-size($size); | ||
line-height: adapter.get-line-height($level: $size, $density: normal); | ||
|
||
._leading { | ||
line-height: adapter.get-line-height($level: $size, $density: normal); | ||
} | ||
|
||
._title { | ||
padding-bottom: adapter.get-spacing-size(map-get(variables.$title-margin-map, $size)); | ||
} | ||
} | ||
|
||
@mixin export { | ||
.in-alert { | ||
@include style; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
$default-options: ( | ||
color: informative, | ||
size: m | ||
); | ||
|
||
$icon-map: ( | ||
informative: "info_on_circle", | ||
positive: "check", | ||
notice: "exclamation_on_triangle", | ||
negative: "exclamation_on_triangle", | ||
); | ||
|
||
$title-margin-map: ( | ||
s: xxs, | ||
m: xs, | ||
l: s | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@use "./mixins"; | ||
@include mixins.export; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@pepabo-inhouse/alert", | ||
"description": "Inhouse Components for the web component", | ||
"version": "1.2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/pepabo/inhouse-components-web.git", | ||
"directory": "packages/alert" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pepabo-inhouse/adapter": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"@pepabo-inhouse/constants": "^1.0.0", | ||
"@pepabo-inhouse/flavor": "^1.2.0", | ||
"@pepabo-inhouse/tokens": "^0.17.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { StoryFn, Meta } from '@storybook/react' | ||
import React from 'react' | ||
import Alert, { Props } from './components/Alert' | ||
|
||
export default { | ||
title: 'Components/Alert', | ||
component: Alert, | ||
size: 'm', | ||
} as Meta | ||
|
||
const Template: StoryFn<Props> = (args) => <Alert {...args} ></Alert> | ||
|
||
export const Index = Template.bind({}) | ||
Index.args = { | ||
children: <>通知を確認してください</> | ||
} | ||
|
||
export const Multiline = Template.bind({}) | ||
Multiline.args = { | ||
children: <> | ||
<div className="_title">更新に失敗しました</div> | ||
以下の入力内容を確認してください。 | ||
<ul> | ||
<li>郵便番号が入力されていません</li> | ||
<li>決済方法が選択されていません</li> | ||
</ul> | ||
</>, | ||
color: "negative" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React, { FC, ReactNode } from 'react' | ||
import { SemanticColor, Size } from './types'; | ||
|
||
export interface Props { | ||
children: ReactNode; | ||
color?: Extract< | ||
SemanticColor, | ||
"informative" | "positive" | "negative" | "notice" | ||
>; | ||
size?: Extract<Size, 's' | 'm' | 'l'>; | ||
} | ||
|
||
const Alert: FC<Props> = (props: Props) => { | ||
const wrapperClasses = ['in-alert'] | ||
const { | ||
color = "informative", | ||
size = "m", | ||
children | ||
} = props | ||
|
||
wrapperClasses.push(`-color-${color}`) | ||
wrapperClasses.push(`-size-${size}`) | ||
|
||
return ( | ||
<div className={wrapperClasses.join(' ')}> | ||
<span className="in-icon _leading"></span> | ||
<div className="_content"> | ||
{ children } | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default Alert |