Skip to content

Commit

Permalink
Merge pull request #8882 from RocketChat/rc-modal
Browse files Browse the repository at this point in the history
[NEW] New Modal component
  • Loading branch information
rodrigok authored Dec 4, 2017
2 parents bed9c33 + 7ba0145 commit 03c2d37
Show file tree
Hide file tree
Showing 11 changed files with 259 additions and 26 deletions.
3 changes: 2 additions & 1 deletion packages/rocketchat-livechat/app/package-lock.json

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

96 changes: 96 additions & 0 deletions packages/rocketchat-theme/client/imports/components/modal.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
.rc-modal {
min-width: 400px;

animation: dropdown-show 0.3s cubic-bezier(0.45, 0.05, 0.55, 0.95);

background: white;

box-shadow: 0 0 2px 0 rgba(47, 52, 61, 0.08), 0 0 12px 0 rgba(47, 52, 61, 0.12);

&-wrapper {
position: fixed;
z-index: 10;
top: 0;
right: 0;
bottom: 0;
left: 0;

display: flex;

padding: 10px;

background: rgba(47, 52, 61, 0.8);
align-items: center;
justify-content: center;
}

&__title {
flex: 1 1 auto;

font-size: 16px;
}

&__close {
cursor: pointer;
transform: rotate(45deg);

font-size: 20px;

&:hover {
color: var(--color-link-active);
}
}

&__header {
display: flex;
flex-direction: row;

margin-bottom: -16px;
padding: 16px;

font-size: 21px;
justify-content: flex-end;
}

&__content {
display: flex;

flex-direction: column;

padding: 16px;

animation: dropdown-show 0.1s cubic-bezier(0.45, 0.05, 0.55, 0.95);

white-space: nowrap;

background-color: var(--modal-background);
}

&__footer {
display: flex;

padding: 16px;

background: #f7f8fa;
justify-content: space-between;

& > .rc-button {
margin: 0;
}
}
}

@media (width <= 400px) {
.rc-modal {
top: initial !important;
bottom: 0;
left: 0 !important;

width: 100%;
min-width: 100%;
max-width: 100%;
margin: 0 16px;

animation: dropup-show 0.3s cubic-bezier(0.45, 0.05, 0.55, 0.95);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@

@keyframes dropdown-show {
0% {
transform: translate(0, -2%);
transform: translate(0, -5%);

opacity: 0;
}
Expand Down
19 changes: 19 additions & 0 deletions packages/rocketchat-theme/client/imports/forms/button.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
.rc-button {
margin: 0.5rem 0;
padding: var(--button-padding);

cursor: pointer;
transition: background-color 0.3s;
text-align: center;

border-width: var(--button-border-width);
border-style: solid;
Expand All @@ -19,12 +21,29 @@
background-color: var(--button-disabled-background);
}

&--nude {
border: none;
background: inherit;
}

&--primary {
color: var(--button-primary-text-color);
border: 0;
background-color: var(--button-primary-background);
}

&--secondary {
color: var(--button-secondary-text-color);
border: 0;
background-color: var(--button-secondary-background);
}

&--cancel {
color: var(--button-primary-text-color);
border: 0;
background-color: var(--button-cancel-color);
}

&--small {
padding: var(--button-padding-small);
}
Expand Down
2 changes: 0 additions & 2 deletions packages/rocketchat-theme/client/imports/general/base_old.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@
}

.upload-preview {
padding: 1rem;

& .upload-preview-file {
height: 200px;

Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-theme/client/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
@import 'imports/components/avatar.css';
@import 'imports/components/badge.css';
@import 'imports/components/popover.css';
@import 'imports/components/modal.css';
@import 'imports/components/tooltip.css';
@import 'imports/components/slider.css';
@import 'imports/components/chip.css';
Expand Down
7 changes: 4 additions & 3 deletions packages/rocketchat-ui-message/startup/messageBoxActions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals fileUpload chatMessages AudioRecorder device popover */
/* globals fileUpload chatMessages AudioRecorder device popover modal */

import mime from 'mime-type/with-db';
import {VRecDialog} from 'meteor/rocketchat:ui-vrecord';
Expand Down Expand Up @@ -90,8 +90,9 @@ RocketChat.messageBox.actions.add('Share', 'My_location', {
const position = RocketChat.Geolocation.get();
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
const text = `<div class="location-preview"><img style="height: 250px; width: 250px;" src="https://maps.googleapis.com/maps/api/staticmap?zoom=14&size=250x250&markers=color:gray%7Clabel:%7C${ latitude },${ longitude }&key=${ RocketChat.settings.get('MapView_GMapsAPIKey') }" /></div>`;
swal({
const text = `<div class="upload-preview"><div class="upload-preview-file" style="background-size: cover; box-shadow: 0 0 0px 1px #dfdfdf; border-radius: 2px; height: 250px; width:100%; max-width: 500px; background-image:url(https://maps.googleapis.com/maps/api/staticmap?zoom=14&size=500x250&markers=color:gray%7Clabel:%7C${ latitude },${ longitude }&key=${ RocketChat.settings.get('MapView_GMapsAPIKey') })" ></div></div>`;

modal.open({
title: t('Share_Location_Title'),
text,
showCancelButton: true,
Expand Down
50 changes: 33 additions & 17 deletions packages/rocketchat-ui/client/lib/fileUpload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals fileUploadHandler, Handlebars, fileUpload */
/* globals fileUploadHandler, Handlebars, fileUpload, modal */
/* exported fileUpload */
import _ from 'underscore';
import s from 'underscore.string';
Expand Down Expand Up @@ -54,12 +54,12 @@ fileUpload = function(filesToUpload) {
function consume() {
const file = files.pop();
if ((file == null)) {
swal.close();
modal.close();
return;
}

if (!RocketChat.fileUploadIsValidContentType(file.file.type)) {
swal({
modal.open({
title: t('FileUpload_MediaType_NotAccepted'),
text: file.file.type || `*.${ s.strRightBack(file.file.name, '.') }`,
type: 'error',
Expand All @@ -69,7 +69,7 @@ fileUpload = function(filesToUpload) {
}

if (file.file.size === 0) {
swal({
modal.open({
title: t('FileUpload_File_Empty'),
type: 'error',
timer: 1000
Expand All @@ -89,8 +89,12 @@ fileUpload = function(filesToUpload) {
</audio>
</div>
<div class='upload-preview-title'>
<input id='file-name' style='display: inherit;' value='${ Handlebars._escape(file.name) }' placeholder='${ t('Upload_file_name') }'>
<input id='file-description' style='display: inherit;' value='' placeholder='${ t('Upload_file_description') }'>
<div class="rc-input__wrapper">
<input class="rc-input__element" id='file-name' style='display: inherit;' value='${ Handlebars._escape(file.name) }' placeholder='${ t('Upload_file_name') }'>
</div>
<div class="rc-input__wrapper">
<input class="rc-input__element" id='file-description' style='display: inherit;' value='' placeholder='${ t('Upload_file_description') }'>
</div>
</div>`;
} else if (file.type === 'video') {
text = `\
Expand All @@ -101,17 +105,25 @@ fileUpload = function(filesToUpload) {
</video>
</div>
<div class='upload-preview-title'>
<input id='file-name' style='display: inherit;' value='${ Handlebars._escape(file.name) }' placeholder='${ t('Upload_file_name') }'>
<input id='file-description' style='display: inherit;' value='' placeholder='${ t('Upload_file_description') }'>
<div class="rc-input__wrapper">
<input class="rc-input__element" id='file-name' style='display: inherit;' value='${ Handlebars._escape(file.name) }' placeholder='${ t('Upload_file_name') }'>
</div>
<div class="rc-input__wrapper">
<input class="rc-input__element" id='file-description' style='display: inherit;' value='' placeholder='${ t('Upload_file_description') }'>
</div>
</div>`;
} else if (file.type === 'image') {
text = `\
<div class='upload-preview'>
<div class='upload-preview-file' style='background-image: url(${ preview })'></div>
</div>
<div class='upload-preview-title'>
<input id='file-name' style='display: inherit;' value='${ Handlebars._escape(file.name) }' placeholder='${ t('Upload_file_name') }'>
<input id='file-description' style='display: inherit;' value='' placeholder='${ t('Upload_file_description') }'>
<div class="rc-input__wrapper">
<input class="rc-input__element" id='file-name' style='display: inherit;' value='${ Handlebars._escape(file.name) }' placeholder='${ t('Upload_file_name') }'>
</div>
<div class="rc-input__wrapper">
<input class="rc-input__element" id='file-description' style='display: inherit;' value='' placeholder='${ t('Upload_file_description') }'>
</div>
</div>`;
} else {
const fileSize = formatBytes(file.file.size);
Expand All @@ -121,12 +133,16 @@ fileUpload = function(filesToUpload) {
<div>${ Handlebars._escape(file.name) } - ${ fileSize }</div>
</div>
<div class='upload-preview-title'>
<input id='file-name' style='display: inherit;' value='${ Handlebars._escape(file.name) }' placeholder='${ t('Upload_file_name') }'>
<input id='file-description' style='display: inherit;' value='' placeholder='${ t('Upload_file_description') }'>
<div class="rc-input__wrapper">
<input class="rc-input__element" id='file-name' style='display: inherit;' value='${ Handlebars._escape(file.name) }' placeholder='${ t('Upload_file_name') }'>
</div>
<div class="rc-input__wrapper">
<input class="rc-input__element" id='file-description' style='display: inherit;' value='' placeholder='${ t('Upload_file_description') }'>
</div>
</div>`;
}

return swal({
return modal.open({
title: t('Upload_file_question'),
text,
showCancelButton: true,
Expand All @@ -136,10 +152,6 @@ fileUpload = function(filesToUpload) {
cancelButtonText: t('Cancel'),
html: true
}, function(isConfirm) {
consume();
if (!isConfirm) {
return;
}

const record = {
name: document.getElementById('file-name').value || file.name || file.file.name,
Expand All @@ -149,6 +161,10 @@ fileUpload = function(filesToUpload) {
description: document.getElementById('file-description').value
};

consume();
if (!isConfirm) {
return;
}
const upload = fileUploadHandler('Uploads', record, file.file);

let uploading = Session.get('uploading') || [];
Expand Down
39 changes: 39 additions & 0 deletions packages/rocketchat-ui/client/views/app/modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<template name="rc_modal">
<div class="rc-modal-wrapper">
<div class="rc-modal rc-modal--{{modalClass}}" data-modal="modal">


{{# if template}}
{{> Template.dynamic template=template data=data}}
{{else}}
<header class="rc-modal__header">
<h1 class="rc-modal__title">{{title}}</h1>
<button class="contextual-bar__close js-close">
{{> icon classes="rc-modal__close" icon="plus"}}
</button>
</header>

<main class="rc-modal__content">
{{# if content}}
{{> Template.dynamic template=content data=data}}
{{/if}}
{{# if text}}
{{# if html}}
{{{text}}}
{{else}}
{{text}}
{{/if}}
{{/if}}
</main>
<div class="rc-modal__footer">
{{# if showCancelButton}}
<input class="rc-button rc-button--nude js-close" type="submit" data-button="cancel" value="{{cancelButtonText}}">
{{/if}}
<input style="background-color:{{confirmButtonColor}}" class="rc-button rc-button--primary js-confirm" type="submit" data-button="create" value="{{confirmButtonText}}">

</div>
{{/if}}

</div>
</div>
</template>
Loading

0 comments on commit 03c2d37

Please sign in to comment.