mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Renamed Dropdown component to DropdownBtn
This commit is contained in:
parent
e1298cfa81
commit
90d4fe72db
5 changed files with 19 additions and 19 deletions
|
@ -4,7 +4,7 @@ import { InputProps } from 'reactstrap/lib/Input';
|
||||||
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 { Dropdown } from '../utils/Dropdown';
|
import { DropdownBtn } from '../utils/DropdownBtn';
|
||||||
import { useToggle } from '../utils/helpers/hooks';
|
import { useToggle } from '../utils/helpers/hooks';
|
||||||
import { DomainsList } from './reducers/domainsList';
|
import { DomainsList } from './reducers/domainsList';
|
||||||
import './DomainSelector.scss';
|
import './DomainSelector.scss';
|
||||||
|
@ -52,7 +52,7 @@ export const DomainSelector = ({ listDomains, value, domainsList, onChange }: Do
|
||||||
</InputGroupAddon>
|
</InputGroupAddon>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
) : (
|
) : (
|
||||||
<Dropdown
|
<DropdownBtn
|
||||||
text={valueIsEmpty ? 'Domain' : `Domain: ${value}`}
|
text={valueIsEmpty ? 'Domain' : `Domain: ${value}`}
|
||||||
className={!valueIsEmpty ? 'domains-dropdown__toggle-btn--active' : ''}
|
className={!valueIsEmpty ? 'domains-dropdown__toggle-btn--active' : ''}
|
||||||
>
|
>
|
||||||
|
@ -70,6 +70,6 @@ export const DomainSelector = ({ listDomains, value, domainsList, onChange }: Do
|
||||||
<DropdownItem onClick={pipe(unselectDomain, showInput)}>
|
<DropdownItem onClick={pipe(unselectDomain, showInput)}>
|
||||||
<i>New domain</i>
|
<i>New domain</i>
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
</Dropdown>
|
</DropdownBtn>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
import { FC } from 'react';
|
import { FC } from 'react';
|
||||||
import { Dropdown as BsDropdown, DropdownMenu, DropdownToggle } from 'reactstrap';
|
import { Dropdown, DropdownMenu, DropdownToggle } from 'reactstrap';
|
||||||
import { useToggle } from './helpers/hooks';
|
import { useToggle } from './helpers/hooks';
|
||||||
import './Dropdown.scss';
|
import './Dropdown.scss';
|
||||||
|
|
||||||
export interface DropdownProps {
|
export interface DropdownBtnProps {
|
||||||
text: string;
|
text: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Dropdown: FC<DropdownProps> = ({ text, disabled = false, className = '', children }) => {
|
export const DropdownBtn: FC<DropdownBtnProps> = ({ text, disabled = false, className = '', children }) => {
|
||||||
const [ isOpen, toggle ] = useToggle();
|
const [ isOpen, toggle ] = useToggle();
|
||||||
const toggleClasses = `dropdown__btn btn-block ${className}`;
|
const toggleClasses = `dropdown__btn btn-block ${className}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BsDropdown isOpen={isOpen} toggle={toggle} disabled={disabled}>
|
<Dropdown isOpen={isOpen} toggle={toggle} disabled={disabled}>
|
||||||
<DropdownToggle caret className={toggleClasses} color="primary">{text}</DropdownToggle>
|
<DropdownToggle caret className={toggleClasses} color="primary">{text}</DropdownToggle>
|
||||||
<DropdownMenu className="w-100">{children}</DropdownMenu>
|
<DropdownMenu className="w-100">{children}</DropdownMenu>
|
||||||
</BsDropdown>
|
</Dropdown>
|
||||||
);
|
);
|
||||||
};
|
};
|
|
@ -1,6 +1,6 @@
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { DropdownItem } from 'reactstrap';
|
import { DropdownItem } from 'reactstrap';
|
||||||
import { Dropdown } from '../Dropdown';
|
import { DropdownBtn } from '../DropdownBtn';
|
||||||
import {
|
import {
|
||||||
DateInterval,
|
DateInterval,
|
||||||
DateRange,
|
DateRange,
|
||||||
|
@ -39,7 +39,7 @@ export const DateRangeSelector = (
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropdown disabled={disabled} text={rangeOrIntervalToString(activeInterval ?? activeDateRange) ?? defaultText}>
|
<DropdownBtn disabled={disabled} text={rangeOrIntervalToString(activeInterval ?? activeDateRange) ?? defaultText}>
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
active={activeInterval === undefined && dateRangeIsEmpty(activeDateRange)}
|
active={activeInterval === undefined && dateRangeIsEmpty(activeDateRange)}
|
||||||
onClick={updateInterval(undefined)}
|
onClick={updateInterval(undefined)}
|
||||||
|
@ -63,6 +63,6 @@ export const DateRangeSelector = (
|
||||||
onEndDateChange={(endDate) => updateDateRange({ ...activeDateRange, endDate })}
|
onEndDateChange={(endDate) => updateDateRange({ ...activeDateRange, endDate })}
|
||||||
/>
|
/>
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
</Dropdown>
|
</DropdownBtn>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { DropdownItem, InputGroup } from 'reactstrap';
|
||||||
import { DomainSelector } from '../../src/domains/DomainSelector';
|
import { DomainSelector } from '../../src/domains/DomainSelector';
|
||||||
import { DomainsList } from '../../src/domains/reducers/domainsList';
|
import { DomainsList } from '../../src/domains/reducers/domainsList';
|
||||||
import { ShlinkDomain } from '../../src/api/types';
|
import { ShlinkDomain } from '../../src/api/types';
|
||||||
import { Dropdown } from '../../src/utils/Dropdown';
|
import { DropdownBtn } from '../../src/utils/DropdownBtn';
|
||||||
|
|
||||||
describe('<DomainSelector />', () => {
|
describe('<DomainSelector />', () => {
|
||||||
let wrapper: ShallowWrapper;
|
let wrapper: ShallowWrapper;
|
||||||
|
@ -24,7 +24,7 @@ describe('<DomainSelector />', () => {
|
||||||
|
|
||||||
it('shows dropdown by default', () => {
|
it('shows dropdown by default', () => {
|
||||||
const input = wrapper.find(InputGroup);
|
const input = wrapper.find(InputGroup);
|
||||||
const dropdown = wrapper.find(Dropdown);
|
const dropdown = wrapper.find(DropdownBtn);
|
||||||
|
|
||||||
expect(input).toHaveLength(0);
|
expect(input).toHaveLength(0);
|
||||||
expect(dropdown).toHaveLength(1);
|
expect(dropdown).toHaveLength(1);
|
||||||
|
@ -34,10 +34,10 @@ describe('<DomainSelector />', () => {
|
||||||
it('allows to toggle between dropdown and input', () => {
|
it('allows to toggle between dropdown and input', () => {
|
||||||
wrapper.find(DropdownItem).last().simulate('click');
|
wrapper.find(DropdownItem).last().simulate('click');
|
||||||
expect(wrapper.find(InputGroup)).toHaveLength(1);
|
expect(wrapper.find(InputGroup)).toHaveLength(1);
|
||||||
expect(wrapper.find(Dropdown)).toHaveLength(0);
|
expect(wrapper.find(DropdownBtn)).toHaveLength(0);
|
||||||
|
|
||||||
wrapper.find('.domains-dropdown__back-btn').simulate('click');
|
wrapper.find('.domains-dropdown__back-btn').simulate('click');
|
||||||
expect(wrapper.find(InputGroup)).toHaveLength(0);
|
expect(wrapper.find(InputGroup)).toHaveLength(0);
|
||||||
expect(wrapper.find(Dropdown)).toHaveLength(1);
|
expect(wrapper.find(DropdownBtn)).toHaveLength(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import { shallow, ShallowWrapper } from 'enzyme';
|
import { shallow, ShallowWrapper } from 'enzyme';
|
||||||
import { DropdownMenu, DropdownToggle } from 'reactstrap';
|
import { DropdownMenu, DropdownToggle } from 'reactstrap';
|
||||||
import { PropsWithChildren } from 'react';
|
import { PropsWithChildren } from 'react';
|
||||||
import { Dropdown, DropdownProps } from '../../src/utils/Dropdown';
|
import { DropdownBtn, DropdownBtnProps } from '../../src/utils/DropdownBtn';
|
||||||
|
|
||||||
describe('<Dropdown />', () => {
|
describe('<DropdownBtn />', () => {
|
||||||
let wrapper: ShallowWrapper;
|
let wrapper: ShallowWrapper;
|
||||||
const createWrapper = (props: PropsWithChildren<DropdownProps>) => {
|
const createWrapper = (props: PropsWithChildren<DropdownBtnProps>) => {
|
||||||
wrapper = shallow(<Dropdown {...props} />);
|
wrapper = shallow(<DropdownBtn {...props} />);
|
||||||
|
|
||||||
return wrapper;
|
return wrapper;
|
||||||
};
|
};
|
Loading…
Reference in a new issue