Skip to content

TagSpaces is an offline, open source, document manager with tagging support

added the support for semi-transparent color for tags and folders

Ilian Sapundshievfb6aca4cf48e
diff --git a/app/components/TransparentBackground.js b/app/components/TransparentBackground.js
new file mode 100644
index 000000000..a2cc59fd6
--- /dev/null
+++ b/app/components/TransparentBackground.js
@@ -0,0 +1,30 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2017-present TagSpaces UG (haftungsbeschraenkt)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License (version 3) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * @flow
+ */
+import React from 'react';
+
+const TransparentBackground = (props) => (
+ <div style={{
+ background: 'url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAMUlEQVQ4T2NkYGAQYcAP3uCTZhw1gGGYhAGBZIA/nYDCgBDAm9BGDWAAJyRCgLaBCAAgXwixzAS0pgAAAABJRU5ErkJggg==")'
+ }}
+ >
+ {props.children}
+ </div>
+);
+
+export default TransparentBackground;
diff --git a/app/components/dialogs/ColorPickerDialog.js b/app/components/dialogs/ColorPickerDialog.js
index ff7b34ecb..d39b5c70f 100644
--- a/app/components/dialogs/ColorPickerDialog.js
+++ b/app/components/dialogs/ColorPickerDialog.js
@@ -41,9 +41,18 @@ type Props = {
};
type State = {
- color: string
+ color: string,
+ colorHex: string
};
+function decimalToHexString(number) {
+ let result = number;
+ if (result < 0) {
+ result = 0xFFFFFFFF + result + 1;
+ }
+ return result.toString(16).toUpperCase();
+}
+
const styles = {
noBorder: {
padding: '0 !important',
@@ -51,29 +60,37 @@ const styles = {
backgroundColor: 'transparent !important'
}
};
-
class ColorPickerDialog extends React.Component<Props, State> {
state = {
- color: ''
+ color: undefined,
+ colorHex: undefined
};
- componentWillReceiveProps = (nextProps: any) => {
- if (this.props.color !== nextProps.color) {
- this.setState({
- color: nextProps.color
- });
- }
- };
+ // static getDerivedStateFromProps(props: Props) {
+ // // if (this.props.color !== nextProps.color) {
+ // if (props.open) {
+ // return {
+ // color: props.color
+ // };
+ // }
+ // return null;
+ // }
onConfirm = () => {
- if (this.state.color && this.state.color.length > 2) {
- this.props.setColor(this.state.color);
+ const { color, colorHex } = this.state;
+ if (color && colorHex) {
+ // const hexAlphaColor = color.hex + (decimalToHexString(color.rgb.a * 256));
+ const hexAlphaColor = colorHex + Math.round(color.a * 255).toString(16);
+ this.props.setColor(hexAlphaColor);
}
this.props.onClose();
};
handleChangeComplete = (color) => {
- this.setState({ color: color.hex });
+ this.setState({
+ color: color.rgb,
+ colorHex: color.hex
+ });
};
renderTitle = () => (
@@ -93,7 +110,7 @@ class ColorPickerDialog extends React.Component<Props, State> {
className={this.props.classes.noBorder}
name="color"
presetColors={this.props.presetColors ? this.props.presetColors : presetColors}
- color={this.state.color}
+ color={this.state.color ? this.state.color : this.props.color}
onChangeComplete={this.handleChangeComplete}
/>
</DialogContent>
diff --git a/app/components/settings/SettingsGeneral.js b/app/components/settings/SettingsGeneral.js
index 3abc4ef1a..e5c41a046 100644
--- a/app/components/settings/SettingsGeneral.js
+++ b/app/components/settings/SettingsGeneral.js
@@ -37,6 +37,7 @@ import {
} from '../../reducers/settings';
import ColorPickerDialog from '../dialogs/ColorPickerDialog';
import AppConfig from '../../config';
+import TransparentBackground from '../TransparentBackground';
const styles = theme => ({
root: {
@@ -47,6 +48,7 @@ const styles = theme => ({
backgroundColor: '#1DD19F'
},
colorChooserButton: {
+ minHeight: 30,
border: '1px solid lightgray'
}
});
@@ -197,17 +199,17 @@ class SettingsGeneral extends React.Component<Props, State> {
<ListItem>
<ListItemText primary={i18n.t('core:tagBackgroundColor')} />
<ListItemSecondaryAction>
- <Button
- data-tid="settingsToggleDefaultTagBackgroundColor"
- className={classes.colorChooserButton}
- size="small"
- style={{
- backgroundColor: this.props.settings.tagBackgroundColor
- }}
- onClick={this.toggleDefaultTagBackgroundColorPicker}
- >
- &nbsp;
- </Button>
+ <TransparentBackground>
+ <Button
+ data-tid="settingsToggleDefaultTagBackgroundColor"
+ className={classes.colorChooserButton}
+ size="small"
+ style={{
+ backgroundColor: this.props.settings.tagBackgroundColor
+ }}
+ onClick={this.toggleDefaultTagBackgroundColorPicker}
+ />
+ </TransparentBackground>
<ColorPickerDialog
open={this.state.displayColorPicker}
setColor={(color) => { this.props.setTagColor(color); }}
@@ -219,16 +221,15 @@ class SettingsGeneral extends React.Component<Props, State> {
<ListItem>
<ListItemText primary={i18n.t('core:tagForegroundColor')} />
<ListItemSecondaryAction>
- <Button
- data-tid="settingsToggleDefaultTagForegroundColor"
- className={classes.colorChooserButton}
- size="small"
- style={{ backgroundColor: this.props.settings.tagTextColor }}
- onClick={this.toggleDefaultTagTextColorPicker}
- >
- &nbsp;
- <div style={styles.textcolor} />
- </Button>
+ <TransparentBackground>
+ <Button
+ data-tid="settingsToggleDefaultTagForegroundColor"
+ className={classes.colorChooserButton}
+ size="small"
+ style={{ backgroundColor: this.props.settings.tagTextColor }}
+ onClick={this.toggleDefaultTagTextColorPicker}
+ />
+ </TransparentBackground>
<ColorPickerDialog
open={this.state.displayTextColorPicker}
setColor={(color) => { this.props.setTagTextColor(color); }}