Skip to content

Commit 7726d28

Browse files
authored
fix(modal): update modal design (#295)
* fix(modal): update modal design and animation #287 * fix(modal): update modal design
1 parent c380b28 commit 7726d28

File tree

5 files changed

+108
-35
lines changed

5 files changed

+108
-35
lines changed

lib/globals/fonts.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
content: "\e802";
2828
}
2929

30-
.icon-cross:before {
31-
content: "\e807";
32-
}
33-
3430
.icon-menu:before {
3531
content: '\e800';
3632
}

lib/modal/index.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { findDOMNode } from 'react-dom';
33
import PropTypes from 'prop-types';
44
import { themr } from 'react-css-themr';
55
import cx from 'classnames';
6+
import { MdClose } from 'react-icons/md';
67
import { transitionEndEventName } from '../globals/helper';
78
import defaultTheme from './theme.module.scss';
89
import '../globals/fonts.scss';
@@ -87,7 +88,7 @@ class Modal extends Component {
8788
const { open } = this.state;
8889
const classes = cx(
8990
theme.modal,
90-
open ? theme['d-block'] : theme['d-none'],
91+
open ? theme['d-block-modal'] : theme['d-none'],
9192
className,
9293
);
9394
const backdrop = cx(
@@ -113,7 +114,16 @@ class Modal extends Component {
113114
this.modalRef = ref;
114115
}}
115116
>
116-
{this.renderModalTitle(title)}
117+
<div className={theme.titleWrapper}>
118+
{this.renderModalTitle(title)}
119+
<span
120+
className={cx(theme.close, 'icon-cross')}
121+
onClick={this.closeModal}
122+
>
123+
&times;
124+
</span>
125+
{title && <hr />}
126+
</div>
117127
<div className={theme['modal-body']} aria-label="card-body">
118128
{children || (
119129
typeof body === 'function'
@@ -122,10 +132,6 @@ class Modal extends Component {
122132
) || null}
123133
</div>
124134
{this.renderModalFooter(footer)}
125-
<i
126-
className={cx(theme.close, 'icon-cross')}
127-
onClick={this.closeModal}
128-
/>
129135
</div>
130136
)}
131137
</div>

lib/modal/tests/accessibility.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('Modal accessibility tests', () => {
8383
toggleModal();
8484
expect(simulatedValue()).equals(expectedValueBeforeClosing);
8585
wrappedComponent
86-
.find('i.icon-cross')
86+
.find('span.icon-cross')
8787
.simulate('click'); // Get the last child element, i.e, close icon.
8888
setTimeout(() => {
8989
expect(simulatedValue()).equals(expectedValueAfterClosing);

lib/modal/tests/render.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ describe('Modal render tests', () => {
6565
const expectedValue = 'card-header';
6666
const simulatedValue = () => wrappedComponent
6767
.find('#modal')
68+
.childAt(0)
6869
.childAt(0);
6970

7071
toggleModal();
@@ -75,7 +76,7 @@ describe('Modal render tests', () => {
7576
const expectedValue = 'card-footer';
7677
const simulatedValue = () => {
7778
const { length } = wrappedComponent.find('#modal').children();
78-
return wrappedComponent.find('#modal').childAt(length - 2);
79+
return wrappedComponent.find('#modal').childAt(length - 1);
7980
};
8081

8182
toggleModal();

lib/modal/theme.module.scss

Lines changed: 93 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
:local(.modal-backdrop) {
2-
background: rgba(0,0,0,0.51);
2+
background: rgba(0, 0, 0, 0.51);
33
position: fixed;
44
top: 0;
55
left: 0;
@@ -9,49 +9,117 @@
99
align-items: center;
1010
justify-content: center;
1111
box-sizing: border-box;
12-
}
12+
}
1313

14-
:local(.animation) {
14+
:local(.animation) {
1515
opacity: 0;
1616
transition: opacity 0.3s;
17-
}
18-
19-
:local(.modal) {
20-
display: none;
17+
}
18+
19+
:local(.titleWrapper) {
20+
display: flex;
21+
width: 100%;
22+
position: relative;
2123
padding: 2%;
22-
padding-bottom: 1%;
23-
box-shadow: 1px 1px 5px rgba(0,0,0,0.5);
24+
box-sizing: border-box;
25+
hr {
26+
border: none;
27+
position: absolute;
28+
left: 0;
29+
width: 100%;
30+
background-color: #888282ab;
31+
bottom: 0;
32+
height: 1px;
33+
margin-bottom: 0;
34+
}
35+
}
36+
37+
:local(.modal) {
38+
display: none;
39+
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.5);
2440
background: white;
2541
width: 50%;
26-
top: calc(30vh + 2em);
42+
top: calc(20vh + 2em);
2743
height: fit-content;
2844
position: fixed;
2945
flex-flow: column;
3046
box-sizing: border-box;
31-
47+
border-radius: 0.3em;
48+
font-variant-ligatures: none;
49+
-webkit-font-variant-ligatures: none;
50+
text-rendering: optimizeLegibility;
51+
-moz-osx-font-smoothing: grayscale;
52+
font-smooth: antialiased;
53+
-webkit-font-smoothing: antialiased;
54+
text-shadow: rgba(0, 0, 0, .01) 0 0 1px;
3255
:local(.modal-title) {
3356
padding: 1% 0%;
3457
font-weight: bold;
3558
box-sizing: border-box;
59+
width: 80%;
60+
text-overflow: ellipsis;
61+
overflow-x: hidden;
62+
white-space: nowrap;
63+
display: inline-block;
64+
text-align: start;
65+
66+
@media only screen and (max-width: 500px) {
67+
padding: 3%;
68+
}
3669
}
37-
3870
:local(.modal-body) {
3971
box-sizing: border-box;
72+
padding: 2%;
73+
text-align: left;
74+
@media only screen and (max-width: 768px) {
75+
padding: 3%;
76+
}
77+
@media only screen and (max-width:500px) {
78+
padding: 5%;
79+
line-height: 1.4em;
80+
}
4081
}
41-
4282
:local(.modal-footer) {
4383
width: 100%;
4484
padding: 1% 2%;
4585
box-sizing: border-box;
86+
@media only screen and (max-width: 768px) {
87+
padding: 2% 3%;
88+
}
89+
}
90+
}
91+
92+
:local(.d-block-modal) {
93+
display: flex;
94+
animation: anim 0.3s linear;
95+
@keyframes anim {
96+
0% {
97+
opacity: 0;
98+
-webkit-transform: scale(0.1);
99+
-moz-transform: scale(0.1);
100+
-ms-transform: scale(0.1);
101+
transform: scale(0.1);
102+
}
103+
100% {
104+
opacity: 1;
105+
-webkit-transform: scale(1);
106+
-moz-transform: scale(1);
107+
-ms-transform: scale(1);
108+
transform: scale(1);
109+
}
46110
}
47111
}
48112

49113
:local(.d-block) {
50114
display: flex;
51115
animation: fadein 0.3s linear;
52116
@keyframes fadein {
53-
0% { opacity: 0; }
54-
100% { opacity: 1; }
117+
0% {
118+
opacity: 0;
119+
}
120+
100% {
121+
opacity: 1;
122+
}
55123
}
56124
}
57125

@@ -60,18 +128,20 @@
60128
}
61129

62130
:local(.close) {
131+
display: flex;
63132
width: fit-content;
133+
height: fit-content;
64134
position: absolute;
65-
right: 0.6em;
66-
top: 0.6em;
135+
font-size: 20px;
136+
color: #1f1e1eab;
137+
right: 1em;
138+
align-items: center;
139+
align-self: center;
67140
cursor: pointer;
68-
font-size: 0.7rem;
69-
background-color: black;
70-
color: white;
71141
}
72142

73143
@media only screen and (max-width: 992px) {
74-
:local(.modal) {
75-
width: 75%;
76-
}
144+
:local(.modal) {
145+
width: 75%;
146+
}
77147
}

0 commit comments

Comments
 (0)