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 { MODES } from '$constants/modes';
|
||||
import { Icon } from '$components/panels/Icon';
|
||||
import { Switch } from '$components/Switch';
|
||||
|
||||
import classnames from 'classnames';
|
||||
|
||||
type Props = {
|
||||
address: String, // initial?
|
||||
|
@ -22,6 +25,7 @@ type Props = {
|
|||
type State = {
|
||||
address: String,
|
||||
title: String,
|
||||
public: Boolean,
|
||||
};
|
||||
|
||||
export class SaveDialog extends React.Component<Props, State> {
|
||||
|
@ -31,6 +35,7 @@ export class SaveDialog extends React.Component<Props, State> {
|
|||
this.state = {
|
||||
address: props.address || '',
|
||||
title: props.title || '',
|
||||
is_public: props.public || false,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -61,15 +66,18 @@ export class SaveDialog extends React.Component<Props, State> {
|
|||
|
||||
onCopy = e => {
|
||||
e.preventDefault();
|
||||
const { host, protocol } = getUrlData();
|
||||
copyToClipboard(`${protocol}//${host}/${this.getAddress()}`);
|
||||
};
|
||||
|
||||
const { host } = getUrlData();
|
||||
copyToClipboard(`http://${host}/${this.getAddress()}`);
|
||||
togglePublic = () => {
|
||||
this.setState({ is_public: !this.state.is_public });
|
||||
};
|
||||
|
||||
render() {
|
||||
const { title } = this.state;
|
||||
const { title, is_public } = this.state;
|
||||
const { save_error, save_finished, save_overwriting, width } = this.props;
|
||||
const { host } = getUrlData();
|
||||
const { host, protocol } = getUrlData();
|
||||
|
||||
return (
|
||||
<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-address-input">
|
||||
<label className="save-address-label">http://{host}/</label>
|
||||
<label className="save-address-label">{protocol}//{host}/</label>
|
||||
<input
|
||||
type="text"
|
||||
value={this.getAddress()}
|
||||
|
@ -101,7 +109,14 @@ export class SaveDialog extends React.Component<Props, State> {
|
|||
</div>
|
||||
|
||||
<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>
|
||||
{ !save_finished &&
|
||||
<div className="button" onClick={this.cancelSaving}>Отмена</div>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
@import 'dialogs.less';
|
||||
@import 'progress.less';
|
||||
@import 'slider.less';
|
||||
@import 'switch.less';
|
||||
|
||||
body {
|
||||
font-family: 'Rubik', sans-serif;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
}
|
||||
|
||||
.save-description {
|
||||
padding: 10px;
|
||||
padding: 5px 10px;
|
||||
}
|
||||
|
||||
.save-title-input {
|
||||
|
@ -47,7 +47,7 @@
|
|||
background: rgba(0, 0, 0, 0.2);
|
||||
border-radius: 2px;
|
||||
display: flex;
|
||||
|
||||
margin-bottom: 5px;
|
||||
input {
|
||||
padding: 5px 5px 5px 2px;
|
||||
background: transparent;
|
||||
|
@ -91,6 +91,7 @@
|
|||
display: flex;
|
||||
padding: 0px;
|
||||
margin-top: 20px;
|
||||
margin-bottom: 5px;
|
||||
|
||||
.button {
|
||||
margin-left: 10px;
|
||||
|
@ -99,6 +100,9 @@
|
|||
|
||||
.save-buttons-text {
|
||||
flex: 1;
|
||||
padding: 0 10px 2px 10px;
|
||||
align-items: center;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.save-description {
|
||||
|
@ -114,3 +118,8 @@
|
|||
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()) => {
|
||||
const [, path, mode] = url.split('/');
|
||||
const { host, hash } = window.location;
|
||||
const { host, hash, protocol } = window.location;
|
||||
|
||||
return {
|
||||
path, mode, host, hash
|
||||
path, mode, host, hash, protocol,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue