mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 02:56:41 +07:00
save: public switch
This commit is contained in:
parent
a1bb4da475
commit
69f23c9e48
6 changed files with 83 additions and 10 deletions
15
src/components/Switch.jsx
Normal file
15
src/components/Switch.jsx
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// @flow
|
||||||
|
import React from 'react';
|
||||||
|
import classnames from 'classnames';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
active: Boolean,
|
||||||
|
|
||||||
|
onPress: Function,
|
||||||
|
}
|
||||||
|
export const Switch = ({ active, onPress = () => {} }: Props) => (
|
||||||
|
<div
|
||||||
|
className={classnames('switch', { active })}
|
||||||
|
onMouseDown={onPress}
|
||||||
|
/>
|
||||||
|
);
|
|
@ -4,6 +4,9 @@ import { toTranslit } from '$utils/format';
|
||||||
import { TIPS } from '$constants/tips';
|
import { TIPS } from '$constants/tips';
|
||||||
import { MODES } from '$constants/modes';
|
import { MODES } from '$constants/modes';
|
||||||
import { Icon } from '$components/panels/Icon';
|
import { Icon } from '$components/panels/Icon';
|
||||||
|
import { Switch } from '$components/Switch';
|
||||||
|
|
||||||
|
import classnames from 'classnames';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
address: String, // initial?
|
address: String, // initial?
|
||||||
|
@ -22,6 +25,7 @@ type Props = {
|
||||||
type State = {
|
type State = {
|
||||||
address: String,
|
address: String,
|
||||||
title: String,
|
title: String,
|
||||||
|
public: Boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
export class SaveDialog extends React.Component<Props, State> {
|
export class SaveDialog extends React.Component<Props, State> {
|
||||||
|
@ -31,6 +35,7 @@ export class SaveDialog extends React.Component<Props, State> {
|
||||||
this.state = {
|
this.state = {
|
||||||
address: props.address || '',
|
address: props.address || '',
|
||||||
title: props.title || '',
|
title: props.title || '',
|
||||||
|
is_public: props.public || false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,15 +66,18 @@ export class SaveDialog extends React.Component<Props, State> {
|
||||||
|
|
||||||
onCopy = e => {
|
onCopy = e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
const { host, protocol } = getUrlData();
|
||||||
|
copyToClipboard(`${protocol}//${host}/${this.getAddress()}`);
|
||||||
|
};
|
||||||
|
|
||||||
const { host } = getUrlData();
|
togglePublic = () => {
|
||||||
copyToClipboard(`http://${host}/${this.getAddress()}`);
|
this.setState({ is_public: !this.state.is_public });
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { title } = this.state;
|
const { title, is_public } = this.state;
|
||||||
const { save_error, save_finished, save_overwriting, width } = this.props;
|
const { save_error, save_finished, save_overwriting, width } = this.props;
|
||||||
const { host } = getUrlData();
|
const { host, protocol } = getUrlData();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="control-dialog control-dialog-medium" style={{ width }}>
|
<div className="control-dialog control-dialog-medium" style={{ width }}>
|
||||||
|
@ -83,7 +91,7 @@ export class SaveDialog extends React.Component<Props, State> {
|
||||||
|
|
||||||
<div className="save-description">
|
<div className="save-description">
|
||||||
<div className="save-address-input">
|
<div className="save-address-input">
|
||||||
<label className="save-address-label">http://{host}/</label>
|
<label className="save-address-label">{protocol}//{host}/</label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={this.getAddress()}
|
value={this.getAddress()}
|
||||||
|
@ -101,7 +109,14 @@ export class SaveDialog extends React.Component<Props, State> {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="save-buttons">
|
<div className="save-buttons">
|
||||||
<div className="save-buttons-text" />
|
<div className={classnames('save-buttons-text pointer', { gray: !is_public })} onClick={this.togglePublic}>
|
||||||
|
<Switch active={is_public} />
|
||||||
|
{
|
||||||
|
is_public
|
||||||
|
? ' В каталоге карт'
|
||||||
|
: ' Только по ссылке'
|
||||||
|
}
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{ !save_finished &&
|
{ !save_finished &&
|
||||||
<div className="button" onClick={this.cancelSaving}>Отмена</div>
|
<div className="button" onClick={this.cancelSaving}>Отмена</div>
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
@import 'dialogs.less';
|
@import 'dialogs.less';
|
||||||
@import 'progress.less';
|
@import 'progress.less';
|
||||||
@import 'slider.less';
|
@import 'slider.less';
|
||||||
|
@import 'switch.less';
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: 'Rubik', sans-serif;
|
font-family: 'Rubik', sans-serif;
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.save-description {
|
.save-description {
|
||||||
padding: 10px;
|
padding: 5px 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.save-title-input {
|
.save-title-input {
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
background: rgba(0, 0, 0, 0.2);
|
background: rgba(0, 0, 0, 0.2);
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
margin-bottom: 5px;
|
||||||
input {
|
input {
|
||||||
padding: 5px 5px 5px 2px;
|
padding: 5px 5px 5px 2px;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
|
@ -91,6 +91,7 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
|
@ -99,6 +100,9 @@
|
||||||
|
|
||||||
.save-buttons-text {
|
.save-buttons-text {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
padding: 0 10px 2px 10px;
|
||||||
|
align-items: center;
|
||||||
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
.save-description {
|
.save-description {
|
||||||
|
@ -114,3 +118,8 @@
|
||||||
padding: 0.25em;
|
padding: 0.25em;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.save-controls {
|
||||||
|
padding: 5px 10px;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
33
src/styles/switch.less
Normal file
33
src/styles/switch.less
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
.switch {
|
||||||
|
height: 1em;
|
||||||
|
width: 2em;
|
||||||
|
border-radius: 0.5em;
|
||||||
|
box-shadow: inset white 0 0 0 0.1em;
|
||||||
|
display: inline-flex;
|
||||||
|
vertical-align: text-top;
|
||||||
|
position: relative;
|
||||||
|
top: 0.05em;
|
||||||
|
margin-right: 0.5em;
|
||||||
|
transition: all 500ms;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
content: ' ';
|
||||||
|
position: absolute;
|
||||||
|
left: 0.2em;
|
||||||
|
top: 0.2em;
|
||||||
|
width: 0.6em;
|
||||||
|
height: 0.6em;
|
||||||
|
border-radius: 0.3em;
|
||||||
|
background: white;
|
||||||
|
transition: all 500ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background: white;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
left: 1.2em;
|
||||||
|
background: #333333;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,10 +6,10 @@ export const replacePath = url => history.replace(url);
|
||||||
|
|
||||||
export const getUrlData = (url = getPath()) => {
|
export const getUrlData = (url = getPath()) => {
|
||||||
const [, path, mode] = url.split('/');
|
const [, path, mode] = url.split('/');
|
||||||
const { host, hash } = window.location;
|
const { host, hash, protocol } = window.location;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path, mode, host, hash
|
path, mode, host, hash, protocol,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue