Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ability to set background colors to entries #49

Merged
merged 6 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/components/AuthEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,18 @@ export default class AuthEntry extends React.Component {
}

render() {
const { service, account, notes } = this.props.entry;
const { service, account, notes, color } = this.props.entry;
const { id, onEdit, onRemove, canEdit } = this.props;
const { token } = this.state;
const timeLeft = this.getTimeLeft();

const entryStyle = {};
if (color) {
entryStyle.backgroundColor = color;
}

return (
<div className="sk-notification sk-base">
<div className="sk-notification sk-base-custom" style={entryStyle}>
<div className="auth-entry">
<div className="auth-details">
<div className="auth-info">
Expand Down
112 changes: 93 additions & 19 deletions app/components/EditEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import QRCodeReader from '@Components/QRCodeReader';
import { secretPattern } from '@Lib/otp';
import { TwitterPicker } from 'react-color';

export default class EditEntry extends React.Component {
static defaultProps = {
Expand All @@ -13,7 +14,8 @@ export default class EditEntry extends React.Component {

this.state = {
id: this.props.id,
entry: this.props.entry
entry: this.props.entry,
showColorPicker: false
};
}

Expand All @@ -25,16 +27,48 @@ export default class EditEntry extends React.Component {
const target = event.target;
const name = target.name;

const value =
name === 'secret' ? this.formatSecret(target.value) : target.value;
const value = name === 'secret' ?
this.formatSecret(target.value) : target.value;

this.setState(state => ({
entry: { ...state.entry, [name]: value }
entry: {
...state.entry,
[name]: value
}
}));
};

handleColorChange = color => {
this.setState(state => ({
entry: {
...state.entry,
color: color.hex
}
}));
};

onSave = e => {
e.preventDefault();
handleSwatchClick = () => {
this.setState({
showColorPicker: !this.state.showColorPicker
});
};

handleColorPickerClose = () => {
this.setState({
showColorPicker: false
});
};

removeColor = () => {
this.setState((state) => {
delete state.entry.color;
return {
entry: state.entry
};
});
};

onSave = () => {
const { id, entry } = this.state;
this.props.onSave({ id, entry });
};
Expand All @@ -57,22 +91,66 @@ export default class EditEntry extends React.Component {
};

render() {
const { id, entry } = this.state;
const { id, entry, showColorPicker: showColorPicker } = this.state;
johnny243 marked this conversation as resolved.
Show resolved Hide resolved

const defaultBgColor = '#fff';
johnny243 marked this conversation as resolved.
Show resolved Hide resolved
const defaultColorOptions = [
johnny243 marked this conversation as resolved.
Show resolved Hide resolved
'#FFB299',
'#FFEBB5',
'#7BDCB5',
'#BDD684',
'#799AE0',
'#7ECEFD',
'#ABB8C3',
'#F27977',
'#FFAFAF',
'#D5C8EB'
];

const swatchStyle = {
width: '36px',
height: '14px',
borderRadius: '2px',
background: `${entry.color ?? defaultBgColor}`,
};

return (
<div className="auth-edit sk-panel">
<div className="sk-panel-content">
<div className="sk-panel-section">
<div className="sk-panel-section-title sk-panel-row">
{id != null ? 'Edit entry' : 'Add new entry'}
{id == null && (
<div className="sk-panel-section-title sk-panel-row">
{entry.color && (
<div className="sk-button danger" onClick={this.removeColor}>
<div className="sk-label">Clear color</div>
</div>
)}
<div className="color-picker-swatch" onClick={this.handleSwatchClick}>
<div style={swatchStyle} />
</div>
</div>
</div>
{showColorPicker && (
<div className="color-picker-popover">
<div className="color-picker-cover" onClick={this.handleColorPickerClose} />
<TwitterPicker
color={entry.color ?? defaultBgColor}
colors={defaultColorOptions}
onChangeComplete={this.handleColorChange}
triangle="top-right"
/>
</div>
)}
{id == null && (
<div className="sk-panel-section sk-panel-hero align-items-center">
<QRCodeReader
onSuccess={this.onQRCodeSuccess}
onError={this.onQRCodeError}
/>
)}
</div>
<form onSubmit={this.onSave}>
</div>
)}
<form>
<input
name="service"
className="sk-input contrast"
Expand Down Expand Up @@ -110,18 +188,14 @@ export default class EditEntry extends React.Component {
/>
<div className="sk-panel-row">
<div className="sk-button-group stretch">
<button
type="button"
onClick={this.props.onCancel}
className="sk-button neutral"
>
<div className="sk-button neutral" onClick={this.props.onCancel}>
<div className="sk-label">Cancel</div>
</button>
<button type="submit" className="sk-button info">
</div>
<div className="sk-button info" onClick={this.onSave}>
<div className="sk-label">
{id != null ? 'Save' : 'Create'}
</div>
</button>
</div>
</div>
</div>
</form>
Expand Down
2 changes: 1 addition & 1 deletion app/components/QRCodeReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class QRCodeReader extends React.Component {

render() {
return (
<div className="file sk-button info">
<div className="sk-button info">
<label className="no-style">
<input
type="file"
Expand Down
39 changes: 38 additions & 1 deletion app/stylesheets/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ html {
position: relative;
width: 24px;
height: 24px;
background: var(--sn-stylekit-background-color);
}

.countdown-pie,
Expand Down Expand Up @@ -271,6 +270,44 @@ html {
// animation: opa 30s steps(1, end) infinite;
}

.color-picker-swatch {
padding: 5px;
background: var(--sn-stylekit-background-color);
border-radius: 1px;
box-shadow: 0 0 0 1px rgba(0,0,0,.1);
display: inline-block;
cursor: pointer;
}

.color-picker-popover {
position: absolute;
z-index: 200;
right: 35px;
top: 125px;
}

.color-picker-cover {
position: fixed;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
}

.align-items-center {
align-items: center;
}

.sk-base-custom {
color: var(--sn-stylekit-foreground-color);
position: relative;
background-color: var(--sn-stylekit-background-color);
overflow: hidden;
border-radius: var(--sn-stylekit-general-border-radius);
border-color: var(--sn-stylekit-border-color);
border: 1px solid var(--sn-stylekit-border-color);
}

// Injected in CountdownPie.js
// @keyframes rota {
// 0% {
Expand Down
2 changes: 1 addition & 1 deletion dist/dist.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dist.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"otplib": "^11.0.1",
"prop-types": "^15.7.2",
"react": "^17.0.1",
"react-color": "^2.19.3",
"react-dom": "^17.0.1",
"regenerator-runtime": "^0.13.2",
"sass-loader": "^11.0.1",
Expand Down
44 changes: 42 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,11 @@
minimatch "^3.0.4"
strip-json-comments "^3.1.1"

"@icons/material@^0.2.4":
version "0.2.4"
resolved "https://registry.yarnpkg.com/@icons/material/-/material-0.2.4.tgz#e90c9f71768b3736e76d7dd6783fc6c2afa88bc8"
integrity sha512-QPcGmICAPbGLGb6F/yNf/KzKqvFx8z5qx3D1yFqVAjoFmXK35EgyW+cJ57Te3CNsmzblwtzakLGFqHPqrfb4Tw==

"@standardnotes/editor-kit@2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@standardnotes/editor-kit/-/editor-kit-2.0.2.tgz#cfe147888406ac1e61f6ef33a8e2523cd5c13638"
Expand Down Expand Up @@ -3756,12 +3761,17 @@ locate-path@^5.0.0:
dependencies:
p-locate "^4.1.0"

lodash-es@^4.17.15:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==

lodash.debounce@^4.0.8:
version "4.0.8"
resolved "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz"
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=

lodash@^4.0.0, lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@~4.17.10:
lodash@^4.0.0, lodash@^4.0.1, lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@~4.17.10:
version "4.17.21"
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
Expand Down Expand Up @@ -3832,6 +3842,11 @@ map-visit@^1.0.0:
dependencies:
object-visit "^1.0.0"

material-colors@^1.2.1:
version "1.2.6"
resolved "https://registry.yarnpkg.com/material-colors/-/material-colors-1.2.6.tgz#6d1958871126992ceecc72f4bcc4d8f010865f46"
integrity sha512-6qE4B9deFBIa9YSpOc9O0Sgc43zTeVYbgDT5veRKSlB2+ZuHNoVVxA1L/ckMUayV9Ay9y7Z/SZCLcGteW9i7bg==

media-typer@0.3.0:
version "0.3.0"
resolved "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz"
Expand Down Expand Up @@ -4626,7 +4641,7 @@ progress@^2.0.0:
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"
integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==

prop-types@^15.7.2:
prop-types@^15.5.10, prop-types@^15.7.2:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
Expand Down Expand Up @@ -4718,6 +4733,19 @@ raw-body@2.4.0:
iconv-lite "0.4.24"
unpipe "1.0.0"

react-color@^2.19.3:
version "2.19.3"
resolved "https://registry.yarnpkg.com/react-color/-/react-color-2.19.3.tgz#ec6c6b4568312a3c6a18420ab0472e146aa5683d"
integrity sha512-LEeGE/ZzNLIsFWa1TMe8y5VYqr7bibneWmvJwm1pCn/eNmrabWDh659JSPn9BuaMpEfU83WTOJfnCcjDZwNQTA==
dependencies:
"@icons/material" "^0.2.4"
lodash "^4.17.15"
lodash-es "^4.17.15"
material-colors "^1.2.1"
prop-types "^15.5.10"
reactcss "^1.2.0"
tinycolor2 "^1.4.1"

react-dom@^17.0.1:
version "17.0.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.1.tgz#1de2560474ec9f0e334285662ede52dbc5426fc6"
Expand All @@ -4740,6 +4768,13 @@ react@^17.0.1:
loose-envify "^1.1.0"
object-assign "^4.1.1"

reactcss@^1.2.0:
version "1.2.3"
resolved "https://registry.yarnpkg.com/reactcss/-/reactcss-1.2.3.tgz#c00013875e557b1cf0dfd9a368a1c3dab3b548dd"
integrity sha512-KiwVUcFu1RErkI97ywr8nvx8dNOpT03rbnma0SSalTYjkrPYaEajR4a/MRt6DZ46K6arDRbWMNHF+xH7G7n/8A==
dependencies:
lodash "^4.0.1"

read-pkg-up@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-1.0.1.tgz"
Expand Down Expand Up @@ -5712,6 +5747,11 @@ thunky@^1.0.2:
resolved "https://registry.npmjs.org/thunky/-/thunky-1.1.0.tgz"
integrity sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA==

tinycolor2@^1.4.1:
version "1.4.2"
resolved "https://registry.yarnpkg.com/tinycolor2/-/tinycolor2-1.4.2.tgz#3f6a4d1071ad07676d7fa472e1fac40a719d8803"
integrity sha512-vJhccZPs965sV/L2sU4oRQVAos0pQXwsvTLkWYdqJ+a8Q5kPFzJTuOFwy7UniPli44NKQGAglksjvOcpo95aZA==

to-fast-properties@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz"
Expand Down