Skip to content

Commit

Permalink
Merge pull request #34 from pepabo/inhouse-alert
Browse files Browse the repository at this point in the history
アプリケーションのステータスを表示する目的として利用されるAlertを追加
  • Loading branch information
piyoppi authored Aug 13, 2024
2 parents 8783e58 + e401e83 commit 5c8c645
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 0 deletions.
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions packages/alert/README.md
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
```
1 change: 1 addition & 0 deletions packages/alert/_index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@forward "./mixins" show style, export;
75 changes: 75 additions & 0 deletions packages/alert/_mixins.scss
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;
}
}
17 changes: 17 additions & 0 deletions packages/alert/_variables.scss
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
)
2 changes: 2 additions & 0 deletions packages/alert/inhouse-alert.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@use "./mixins";
@include mixins.export;
21 changes: 21 additions & 0 deletions packages/alert/package.json
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"
}
}
1 change: 1 addition & 0 deletions packages/components-web/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
@forward "@pepabo-inhouse/table" as table-*;
@forward "@pepabo-inhouse/textfield" as textfield-*;
@forward "@pepabo-inhouse/snackbar" as snackbar-*;
@forward "@pepabo-inhouse/alert" as alert-*;
2 changes: 2 additions & 0 deletions packages/components-web/inhouse-components-web.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@use "@pepabo-inhouse/table";
@use "@pepabo-inhouse/textfield";
@use "@pepabo-inhouse/snackbar";
@use "@pepabo-inhouse/alert";

// @import が存在しているので最初に flavor を読む
// see: https://git.pepabo.com/inhouse/components-web/issues/355
Expand All @@ -47,3 +48,4 @@
@include table.export;
@include textfield.export;
@include snackbar.export;
@include alert.export;
1 change: 1 addition & 0 deletions packages/components-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@pepabo-inhouse/table": "^1.2.0",
"@pepabo-inhouse/textfield": "^1.2.0",
"@pepabo-inhouse/thumbnail": "^1.2.0",
"@pepabo-inhouse/alert": "^1.2.0",
"@pepabo-inhouse/tokens": "^0.17.0",
"autoprefixer": "10.4.14",
"cssnano": "5.1.15",
Expand Down
1 change: 1 addition & 0 deletions packages/stories-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@pepabo-inhouse/table": "^1.2.0",
"@pepabo-inhouse/textfield": "^1.2.0",
"@pepabo-inhouse/thumbnail": "^1.2.0",
"@pepabo-inhouse/alert": "^1.2.0",
"@pepabo-inhouse/tokens": "^0.17.0",
"@storybook/addon-essentials": "^7.0.6",
"@storybook/react": "^7.0.6",
Expand Down
29 changes: 29 additions & 0 deletions packages/stories-web/src/alert.stories.tsx
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"
}
34 changes: 34 additions & 0 deletions packages/stories-web/src/components/Alert.tsx
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

0 comments on commit 5c8c645

Please sign in to comment.