├── .babelrc ├── .editorconfig ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .npmignore ├── .npmrc ├── .prettierignore ├── .prettierrc ├── .storybook ├── config.js └── webpack.config.js ├── LICENSE ├── README.md ├── examples └── index.html ├── index.js ├── package-lock.json ├── package.json ├── res └── demo.gif ├── src ├── MessageModal │ ├── colors.js │ ├── index.js │ ├── keyframes.js │ └── styles.js └── index.js ├── stories └── index.stories.js └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env", 4 | "@babel/react" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [{package.json,*.yml}] 15 | indent_style = space 16 | indent_size = 2 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # 事象説明 2 | 3 | ## スクリーンショット 4 | 5 | ## 原因 6 | 7 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # 目的 2 | 3 | ## スクリーンショット 4 | 5 | ## やったこと 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .DS_Store 3 | lib/ 4 | examples/index.js 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | LICENSE 2 | src/ 3 | res/ 4 | examples/ 5 | README.md 6 | .babelrc 7 | .npmrc 8 | .prettierrc 9 | .prettierignore 10 | .editorconfig 11 | .keep 12 | webpack.config.js 13 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | save-exact=true 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | lib 3 | examples 4 | res 5 | package.json 6 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 80, 3 | "semi": false, 4 | "singleQuote": true, 5 | "jsxSingleQuote": true, 6 | "trailingComma": "es5", 7 | "jsxBracketSameLine": true 8 | } 9 | -------------------------------------------------------------------------------- /.storybook/config.js: -------------------------------------------------------------------------------- 1 | import { configure } from '@storybook/react' 2 | 3 | // automatically import all files ending in *.stories.js 4 | const req = require.context('../stories', true, /.stories.js$/) 5 | function loadStories() { 6 | req.keys().forEach(filename => req(filename)) 7 | } 8 | 9 | configure(loadStories, module) 10 | -------------------------------------------------------------------------------- /.storybook/webpack.config.js: -------------------------------------------------------------------------------- 1 | // you can use this file to add your custom webpack plugins, loaders and anything you like. 2 | // This is just the basic way to add additional webpack configurations. 3 | // For more information refer the docs: https://storybook.js.org/configurations/custom-webpack-config 4 | 5 | // IMPORTANT 6 | // When you add this file, we won't add the default configurations which is similar 7 | // to "React Create App". This only has babel loader to load JavaScript. 8 | 9 | module.exports = { 10 | plugins: [ 11 | // your custom plugins 12 | ], 13 | module: { 14 | rules: [ 15 | // add your custom rules. 16 | ], 17 | }, 18 | } 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 yui540 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # @yui540/react-message-modal 2 | 3 | 『メッセージが届いています。』 4 | 5 | デモサイトは[こちら](https://yui540-react-message-modal.netlify.com/) 6 | 7 | ![demo](./res/demo.gif) 8 | 9 | - npm 10 | - [@yui540/react-message-modal](https://www.npmjs.com/package/@yui540/react-message-modal) 11 | - 開発者 12 | - yui540 13 | - [Twitter: @yui540](https://twitter.com/yui540) 14 | - [HP](https://yui540.graphics/) 15 | 16 | ## 使い方 17 | 18 | まず、自身のプロジェクトに`@yui540/react-message-modal`をインストールしてください。 19 | 20 | ```bash 21 | $ npm i @yui540/react-message-modal -S 22 | ``` 23 | 24 | あとは、自身のプロジェクトの組み込みたい箇所にコンポーネントをマウントしてください。 25 | 26 | props 等の詳細は下記のソースコードのコメントをご参考ください。 27 | 28 | ```javascript 29 | import React from 'react' 30 | import { render } from 'react-dom' 31 | 32 | // MessageModalに渡すprops一覧です 33 | const className = 'message-modal' 34 | const title = 'メッセージが届いています。' 35 | const fontColor = '#5d3523' 36 | const okColor = '#90bdbd' 37 | const cancelColor = '#ea8b98' 38 | const mainColor = '#e4d6ce' 39 | const subColor = '#ffffff' 40 | const onClose = () => console.log('close') 41 | const sp = !(window.innerWidth > 760) 42 | const props = { 43 | title, // [type: string] メッセージモーダルのタイトル 44 | fontColor, // [type: string][options] モーダルのタイトル色 45 | okColor, // [type: string][options] OKボタンの色 46 | cancelColor, // [type: string][options] キャンセルボタンの色 47 | mainColor, // [type: string][options] モーダルのメインカラー 48 | subColor, // [type: string][options] モーダルのサブカラー 49 | onClose, // [type: func][options] モーダルを閉じた時に呼ばれる関数 50 | sp, // [type: bool][options] スマートフォンか否か 51 | className, // [type: string][options] class名 52 | } 53 | 54 | /* 55 | 各色のデフォルトの値は下記の通り 56 | 57 | fontColor = '#5d3523 58 | okColor = '#90bdbd' 59 | cancelColor = '#ea8b98' 60 | mainColor = '#e4d6ce' 61 | subColor = '#ffffff' 62 | */ 63 | 64 | render( 65 | // MessageModalの子要素がメッセージの内容になります 66 |
67 |

はじめまして。

68 |

はじめまして。yui540です。

69 |
70 |
, 71 | document.querySelector('#root') 72 | ) 73 | ``` 74 | -------------------------------------------------------------------------------- /examples/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @yui540/react-message-modal 7 | 8 | 9 |
10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./lib') 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@yui540/react-message-modal", 3 | "version": "1.0.1", 4 | "description": "『メッセージが届いています。』", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "storybook": "start-storybook -p 6006", 9 | "build": "babel src/MessageModal --out-dir lib", 10 | "serve": "cross-env MODE=development webpack-dev-server", 11 | "watch": "cross-env MODE=development webpack --watch", 12 | "webpack:dev": "cross-env MODE=development webpack", 13 | "webpack:prod": "cross-env MODE=production webpack", 14 | "webpack": "npm-run-all webpack:prod", 15 | "prepublish": "rm -rf lib && npm run build", 16 | "fmt": "prettier --write \"**/*.{js,jsx,json}\"", 17 | "build-storybook": "build-storybook" 18 | }, 19 | "husky": { 20 | "hooks": { 21 | "pre-commit": "lint-staged" 22 | } 23 | }, 24 | "lint-staged": { 25 | "*.{js,jsx,json}": [ 26 | "prettier --write", 27 | "git add" 28 | ] 29 | }, 30 | "repository": { 31 | "type": "git", 32 | "url": "git+https://github.com/yui540/react-message-modal.git" 33 | }, 34 | "keywords": [], 35 | "author": "yui540 (https://yui540.graphics)", 36 | "license": "MIT", 37 | "bugs": { 38 | "url": "https://github.com/yui540/react-message-modal/issues" 39 | }, 40 | "homepage": "https://github.com/yui540/react-message-modal#readme", 41 | "devDependencies": { 42 | "@babel/cli": "7.2.3", 43 | "@babel/core": "7.3.3", 44 | "@babel/polyfill": "7.2.5", 45 | "@babel/preset-env": "7.3.1", 46 | "@babel/preset-react": "7.0.0", 47 | "@storybook/cli": "4.1.11", 48 | "babel-loader": "8.0.5", 49 | "cross-env": "5.2.0", 50 | "husky": "1.3.1", 51 | "lint-staged": "8.1.4", 52 | "npm-run-all": "4.1.5", 53 | "prettier": "1.16.4", 54 | "react": "16.8.2", 55 | "react-dom": "16.8.2", 56 | "webpack": "4.29.4", 57 | "webpack-cli": "3.2.3", 58 | "webpack-dev-server": "3.1.14", 59 | "@storybook/react": "^4.1.11", 60 | "@storybook/addon-actions": "^4.1.11", 61 | "@storybook/addon-links": "^4.1.11", 62 | "@storybook/addons": "^4.1.11" 63 | }, 64 | "dependencies": { 65 | "proptypes": "1.1.0", 66 | "styled-components": "4.1.3" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /res/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui540/react-message-modal/dcad21fcb3a912e30f7a633ee67197ad449ad8b6/res/demo.gif -------------------------------------------------------------------------------- /src/MessageModal/colors.js: -------------------------------------------------------------------------------- 1 | export const $fontColor = '#5d3523' 2 | export const $okColor = '#90bdbd' 3 | export const $cancelColor = '#ea8b98' 4 | export const $mainColor = '#e4d6ce' 5 | export const $subColor = '#ffffff' 6 | -------------------------------------------------------------------------------- /src/MessageModal/index.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'proptypes' 3 | import { 4 | Container, 5 | HeaderWrapper, 6 | Title, 7 | MainColumnWrapper, 8 | Inner, 9 | FooterWrapper, 10 | OkButton, 11 | CancelButton, 12 | } from './styles' 13 | import { 14 | $fontColor, 15 | $okColor, 16 | $cancelColor, 17 | $mainColor, 18 | $subColor, 19 | } from './colors' 20 | 21 | const Header = ({ 22 | title, 23 | fontColor = $fontColor, 24 | mainColor = $mainColor, 25 | subColor = $subColor, 26 | isOpenMessage, 27 | }) => ( 28 | 32 | 33 | {title} 34 | 35 | 36 | ) 37 | 38 | const MainColumn = ({ 39 | subColor = $subColor, 40 | fontColor = $fontColor, 41 | isOpenMessage, 42 | children, 43 | getMessageHeight, 44 | messageHeight, 45 | }) => ( 46 | 51 | {children} 52 | 53 | ) 54 | 55 | const Footer = ({ 56 | fontColor = $fontColor, 57 | okColor = $okColor, 58 | cancelColor = $cancelColor, 59 | mainColor = $mainColor, 60 | subColor = $subColor, 61 | isOpenMessage, 62 | closeModal, 63 | openMessage, 64 | sp, 65 | }) => ( 66 | 67 | 74 |
75 |
76 |
77 |
78 | 79 | 86 |
87 |
88 |
89 |
90 | 91 | 92 | ) 93 | 94 | export default class MessageModal extends Component { 95 | constructor(props) { 96 | super(props) 97 | 98 | this.state = { 99 | messageHeight: 0, 100 | isClose: false, 101 | isOpenMessage: false, 102 | } 103 | } 104 | 105 | componentDidMount() { 106 | const height = document 107 | .querySelector('.message-modal__inner') 108 | .getBoundingClientRect().height 109 | 110 | this.setState({ messageHeight: height }) 111 | } 112 | 113 | getMessageHeight(height) { 114 | this.setState({ messageHeight: height }) 115 | } 116 | 117 | openMessage() { 118 | this.setState({ isOpenMessage: true }) 119 | } 120 | 121 | closeModal() { 122 | if (this.state.isOpenMessage) this.setState({ isOpenMessage: false }) 123 | else this.setState({ isClose: true }) 124 | } 125 | 126 | onCloseModal() { 127 | this.setState({ isClose: 'delete' }) 128 | 129 | this.props.onClose && this.props.onClose() 130 | } 131 | 132 | render() { 133 | const { sp = false, className = 'message-modal' } = this.props 134 | const { isClose } = this.state 135 | 136 | return ( 137 | { 142 | if (e.animationName === 'message-modal__close') this.onCloseModal() 143 | }}> 144 |
145 | 150 |