From 1818ea1e3bb94994c9d6f924b319b1608454dcf0 Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Tue, 22 Nov 2022 12:02:27 -0600 Subject: [PATCH] dropdown changes --- client/components/combobox.jsx | 68 +++++++++++++++++++ client/components/combobox.less | 20 ++++++ .../editor/metadataEditor/metadataEditor.jsx | 40 ++++++----- 3 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 client/components/combobox.jsx create mode 100644 client/components/combobox.less diff --git a/client/components/combobox.jsx b/client/components/combobox.jsx new file mode 100644 index 000000000..e4d5e77e5 --- /dev/null +++ b/client/components/combobox.jsx @@ -0,0 +1,68 @@ +const React = require('react'); +const createClass = require('create-react-class'); +const _ = require('lodash'); +const cx = require('classnames'); +require('./combobox.less'); + +const Dropdown = { + combo : createClass({ + displayName : 'Dropdown.combo', + getDefaultProps : function() { + return { + trigger : 'hover' + }; + }, + getInitialState : function() { + return { + showDropdown : false + }; + }, + componentDidMount : function() { + if(this.props.trigger == 'click') + document.addEventListener('click', this.handleClickOutside); + }, + componentWillUnmount : function() { + if(this.props.trigger == 'click') + document.removeEventListener('click', this.handleClickOutside); + }, + handleClickOutside : function(e){ + // Close dropdown when clicked outside + if(this.refs.dropdown && !this.refs.dropdown.contains(e.target)) { + this.handleDropdown(false); + } + }, + handleDropdown : function(show){ + this.setState({ + showDropdown : show + }); + }, + renderDropdown : function(dropdownChildren){ + if(!this.state.showDropdown) return null; + + return ( +
+ {dropdownChildren} +
+ ); + }, + render : function () { + const dropdownChildren = React.Children.map(this.props.children, (child, i)=>{ + // Ignore the first child + if(i < 1) return; + return child; + }); + return ( +
{this.handleDropdown(true);} : undefined} + onClick= {this.props.trigger == 'click' ? ()=>{this.handleDropdown(true);} : undefined} + onMouseLeave={this.props.trigger == 'hover' ? ()=>{this.handleDropdown(false);} : undefined}> + {this.props.children[0] || this.props.children /*children is not an array when only one child*/} + {this.renderDropdown(dropdownChildren)} +
+ ); + } + }) +}; + +module.exports = Dropdown; \ No newline at end of file diff --git a/client/components/combobox.less b/client/components/combobox.less new file mode 100644 index 000000000..2d0109c8e --- /dev/null +++ b/client/components/combobox.less @@ -0,0 +1,20 @@ +.dropdown-container { + position:relative; + .dropdown-options { + position:absolute; + background-color: rgb(227, 227, 227); + z-index: 100; + width: 100%; + border: 1px solid #444; + .item { + font-size: 12px; + font-family: OpenSans; + padding: 5px; + &:hover { + filter: brightness(120%); + } + } + + } + +} diff --git a/client/homebrew/editor/metadataEditor/metadataEditor.jsx b/client/homebrew/editor/metadataEditor/metadataEditor.jsx index 736641a0d..abb00fbb5 100644 --- a/client/homebrew/editor/metadataEditor/metadataEditor.jsx +++ b/client/homebrew/editor/metadataEditor/metadataEditor.jsx @@ -6,6 +6,7 @@ const _ = require('lodash'); const cx = require('classnames'); const request = require('superagent'); const Nav = require('naturalcrit/nav/nav.jsx'); +const Dropdown = require('client/components/combobox.jsx'); const StringArrayEditor = require('../stringArrayEditor/stringArrayEditor.jsx'); const Themes = require('themes/themes.json'); @@ -108,6 +109,11 @@ const MetadataEditor = createClass({ this.props.onChange(this.props.metadata); }, + handleLanguage : function(language){ + this.props.metadata.lang = language; + this.props.onChange(this.props.metadata); + }, + handleDelete : function(){ if(this.props.metadata.authors && this.props.metadata.authors.length <= 1){ if(!confirm('Are you sure you want to delete this brew? Because you are the only owner of this brew, the document will be deleted permanently.')) return; @@ -191,20 +197,20 @@ const MetadataEditor = createClass({ if(this.props.metadata.renderer == 'legacy') { dropdown = - +
{`Themes are not supported in the Legacy Renderer`}
-
; + ; } else { dropdown = - +
{`${_.upperFirst(currentTheme.renderer)} : ${currentTheme.name}`}
{/*listThemes('Legacy')*/} {listThemes('V3')} -
; + ; } return
@@ -251,22 +257,22 @@ const MetadataEditor = createClass({ const listLanguages = ()=>{ return _.map(langCodes.sort(), (code, index)=>{ const languageNames = new Intl.DisplayNames([code], { type: 'language' }); - return ; + return
this.handleLanguage(code)}>{`${code}`}
; }); }; return
- this.handleFieldChange('lang', e)} - list='languageList' - placeholder={`'en', 'es', 'de' for example`} - name='brewLanguage' - /> - + +
+ this.handleFieldChange('lang', e)} + placeholder='en' + /> +
{listLanguages()} -
+
; }, @@ -275,10 +281,8 @@ const MetadataEditor = createClass({
this.handleFieldChange('title', e)} - name='brewTitle' - /> + defaultValue={this.props.metadata.title} + onChange={(e)=>this.handleFieldChange('title', e)} />