Improved design on domains dropdown

This commit is contained in:
Alejandro Celaya 2020-11-28 09:34:41 +01:00
parent 983e4db3b1
commit 369fcf2f6a
5 changed files with 17 additions and 7 deletions

View file

@ -5,10 +5,16 @@
.domains-dropdown__toggle-btn.domains-dropdown__toggle-btn:active { .domains-dropdown__toggle-btn.domains-dropdown__toggle-btn:active {
text-align: left; text-align: left;
color: #6c757d; color: #6c757d;
border-color: #6c757d; border-color: #ced4da;
background-color: white; background-color: white;
} }
.domains-dropdown__toggle-btn--active.domains-dropdown__toggle-btn--active,
.domains-dropdown__toggle-btn--active.domains-dropdown__toggle-btn--active:hover,
.domains-dropdown__toggle-btn--active.domains-dropdown__toggle-btn--active:active {
color: #495057;
}
.domains-dropdown__toggle-btn.domains-dropdown__toggle-btn::after { .domains-dropdown__toggle-btn.domains-dropdown__toggle-btn::after {
right: .75rem; right: .75rem;

View file

@ -14,6 +14,7 @@ import {
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faUndo } from '@fortawesome/free-solid-svg-icons'; import { faUndo } from '@fortawesome/free-solid-svg-icons';
import { isEmpty, pipe } from 'ramda'; import { isEmpty, pipe } from 'ramda';
import classNames from 'classnames';
import { useToggle } from '../utils/helpers/hooks'; import { useToggle } from '../utils/helpers/hooks';
import { DomainsList } from './reducers/domainsList'; import { DomainsList } from './reducers/domainsList';
import './DomainsDropdown.scss'; import './DomainsDropdown.scss';
@ -32,7 +33,6 @@ export const DomainsDropdown = ({ listDomains, value, domainsList, onChange }: D
const [ inputDisplayed,, showInput, hideInput ] = useToggle(); const [ inputDisplayed,, showInput, hideInput ] = useToggle();
const [ isDropdownOpen, toggleDropdown ] = useToggle(); const [ isDropdownOpen, toggleDropdown ] = useToggle();
const { domains } = domainsList; const { domains } = domainsList;
const defaultDomain = domains.find(({ isDefault }) => isDefault);
const valueIsEmpty = isEmpty(value); const valueIsEmpty = isEmpty(value);
const unselectDomain = () => onChange(''); const unselectDomain = () => onChange('');
@ -58,8 +58,9 @@ export const DomainsDropdown = ({ listDomains, value, domainsList, onChange }: D
</InputGroup> </InputGroup>
) : ( ) : (
<Dropdown isOpen={isDropdownOpen} toggle={toggleDropdown}> <Dropdown isOpen={isDropdownOpen} toggle={toggleDropdown}>
<DropdownToggle caret className="domains-dropdown__toggle-btn btn-block"> <DropdownToggle caret className={classNames('domains-dropdown__toggle-btn btn-block', { 'domains-dropdown__toggle-btn--active': !valueIsEmpty })}>
Domain: {valueIsEmpty ? defaultDomain?.domain : value} {valueIsEmpty && <>Domain</>}
{!valueIsEmpty && <>Domain: {value}</>}
</DropdownToggle> </DropdownToggle>
<DropdownMenu className="domains-dropdown__menu"> <DropdownMenu className="domains-dropdown__menu">
{domains.map(({ domain, isDefault }) => ( {domains.map(({ domain, isDefault }) => (

View file

@ -156,6 +156,7 @@ const CreateShortUrl = (
<ForServerVersion minVersion="1.16.0"> <ForServerVersion minVersion="1.16.0">
<div className="mb-4 text-right"> <div className="mb-4 text-right">
<Checkbox <Checkbox
inline
className="mr-2" className="mr-2"
checked={shortUrlCreation.findIfExists} checked={shortUrlCreation.findIfExists}
onChange={(findIfExists) => setShortUrlCreation({ ...shortUrlCreation, findIfExists })} onChange={(findIfExists) => setShortUrlCreation({ ...shortUrlCreation, findIfExists })}

View file

@ -7,6 +7,7 @@ export interface BooleanControlProps {
checked?: boolean; checked?: boolean;
onChange?: (checked: boolean, e: ChangeEvent<HTMLInputElement>) => void; onChange?: (checked: boolean, e: ChangeEvent<HTMLInputElement>) => void;
className?: string; className?: string;
inline?: boolean;
} }
interface BooleanControlWithTypeProps extends BooleanControlProps { interface BooleanControlWithTypeProps extends BooleanControlProps {
@ -14,7 +15,7 @@ interface BooleanControlWithTypeProps extends BooleanControlProps {
} }
const BooleanControl: FC<BooleanControlWithTypeProps> = ( const BooleanControl: FC<BooleanControlWithTypeProps> = (
{ checked = false, onChange = identity, className, children, type }, { checked = false, onChange = identity, className, children, type, inline = false },
) => { ) => {
const id = uuid(); const id = uuid();
const onChecked = (e: ChangeEvent<HTMLInputElement>) => onChange(e.target.checked, e); const onChecked = (e: ChangeEvent<HTMLInputElement>) => onChange(e.target.checked, e);
@ -22,9 +23,10 @@ const BooleanControl: FC<BooleanControlWithTypeProps> = (
'custom-switch': type === 'switch', 'custom-switch': type === 'switch',
'custom-checkbox': type === 'checkbox', 'custom-checkbox': type === 'checkbox',
}; };
const style = inline ? { display: 'inline-block' } : {};
return ( return (
<span className={classNames('custom-control', typeClasses, className)}> <span className={classNames('custom-control', typeClasses, className)} style={style}>
<input type="checkbox" className="custom-control-input" id={id} checked={checked} onChange={onChecked} /> <input type="checkbox" className="custom-control-input" id={id} checked={checked} onChange={onChecked} />
<label className="custom-control-label" htmlFor={id}>{children}</label> <label className="custom-control-label" htmlFor={id}>{children}</label>
</span> </span>

View file

@ -13,7 +13,7 @@ describe('<CreateShortUrl />', () => {
const createShortUrl = jest.fn(async () => Promise.resolve()); const createShortUrl = jest.fn(async () => Promise.resolve());
beforeEach(() => { beforeEach(() => {
const CreateShortUrl = createShortUrlsCreator(TagsSelector, () => null, () => null); const CreateShortUrl = createShortUrlsCreator(TagsSelector, () => null, () => null, () => null);
wrapper = shallow( wrapper = shallow(
<CreateShortUrl <CreateShortUrl