Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Enhancement] UI input style improvement (#1284)

Shan Heb6fd39166be2
diff --git a/examples/demo-app/src/components/load-data-modal/load-remote-map.js b/examples/demo-app/src/components/load-data-modal/load-remote-map.js
index 6e808aa8d..b221c1036 100644
--- a/examples/demo-app/src/components/load-data-modal/load-remote-map.js
+++ b/examples/demo-app/src/components/load-data-modal/load-remote-map.js
@@ -24,6 +24,7 @@ import PropTypes from 'prop-types';
import styled from 'styled-components';
import {CORS_LINK} from '../../constants/default-settings';
import {FormattedHTMLMessage, FormattedMessage} from 'react-intl';
+import {Button} from 'kepler.gl/components';
const propTypes = {
onLoadRemoteMap: PropTypes.func.isRequired
@@ -74,11 +75,6 @@ export const StyledInputLabel = styled.div`
}
`;
-export const StyledBtn = styled.button`
- background-color: ${props => props.theme.primaryBtnActBgd};
- color: ${props => props.theme.primaryBtnActColor};
-`;
-
export const StyledError = styled.div`
color: red;
`;
@@ -144,9 +140,9 @@ class LoadRemoteMap extends Component {
value={this.state.dataUrl}
error={this.props.error}
/>
- <StyledBtn type="submit" onClick={this.onLoadRemoteMap}>
+ <Button type="submit" cta size="small" onClick={this.onLoadRemoteMap}>
<FormattedMessage id={'loadRemoteMap.fetch'} />
- </StyledBtn>
+ </Button>
</StyledFromGroup>
{this.props.error && <Error error={this.props.error} url={this.props.option.dataUrl} />}
</InputForm>
diff --git a/src/components/common/checkbox.js b/src/components/common/checkbox.js
index 76f6cb64c..597970cdd 100644
--- a/src/components/common/checkbox.js
+++ b/src/components/common/checkbox.js
@@ -31,7 +31,11 @@ const StyledSwitchInput = styled.label`
`;
const StyledCheckboxInput = styled.label`
- ${props => props.theme.inputCheckbox}
+ ${props => props.theme.inputCheckbox};
+`;
+
+const StyledRadiuInput = styled.label`
+ ${props => props.theme.inputRadio};
`;
const HiddenInput = styled.input`
@@ -98,7 +102,13 @@ export default class Checkbox extends Component {
htmlFor: this.props.id
};
- const LabelElement = this.props.type === 'checkbox' ? StyledCheckboxInput : StyledSwitchInput;
+ const LabelElement =
+ this.props.type === 'checkbox'
+ ? StyledCheckboxInput
+ : this.props.type === 'radio'
+ ? StyledRadiuInput
+ : StyledSwitchInput;
+
return (
<StyledCheckbox className={classnames('kg-checkbox', this.props.className)}>
<HiddenInput {...inputProps} />
diff --git a/src/components/common/field-selector.js b/src/components/common/field-selector.js
index 057b46c37..0c0041598 100644
--- a/src/components/common/field-selector.js
+++ b/src/components/common/field-selector.js
@@ -78,7 +78,7 @@ const FieldType = PropTypes.oneOfType([
})
]);
-const FieldSelectorFactory = FieldListItemFactory => {
+function FieldSelectorFactory(FieldListItemFactory) {
class FieldSelector extends Component {
static propTypes = {
fields: PropTypes.oneOfType([PropTypes.array, PropTypes.arrayOf(FieldType)]),
@@ -177,7 +177,7 @@ const FieldSelectorFactory = FieldListItemFactory => {
}
}
return FieldSelector;
-};
+}
FieldSelectorFactory.deps = [FieldListItemFactoryFactory];
export default FieldSelectorFactory;
diff --git a/src/components/common/info-helper.js b/src/components/common/info-helper.js
index 06987b30f..ab32540a0 100644
--- a/src/components/common/info-helper.js
+++ b/src/components/common/info-helper.js
@@ -33,7 +33,8 @@ const StyledInfoHelper = styled.div`
color: ${props => props.theme.labelColor};
display: inline-flex;
.info-helper__content {
- max-width: 100px;
+ width: ${props => (props.width ? `${props.width}px` : 'auto')};
+ max-width: ${props => (props.width ? 'auto' : '100px')};
}
:hover {
cursor: pointer;
@@ -46,12 +47,17 @@ function InfoHelperFactory() {
description: PropTypes.string.isRequired,
containerClass: PropTypes.string
};
- const InfoHelper = ({description, property, containerClass, id}) => {
+ const InfoHelper = ({description, property, containerClass, width, id}) => {
// TODO: move intl out
const intl = useIntl();
return (
- <StyledInfoHelper className={`info-helper ${containerClass || ''}`} data-tip data-for={id}>
+ <StyledInfoHelper
+ className={`info-helper ${containerClass || ''}`}
+ width={width}
+ data-tip
+ data-for={id}
+ >
<Docs height="16px" />
<Tooltip id={id} effect="solid">
<div className="info-helper__content">
diff --git a/src/components/common/item-selector/item-selector.js b/src/components/common/item-selector/item-selector.js
index 1ce85af16..19ccfaf63 100644
--- a/src/components/common/item-selector/item-selector.js
+++ b/src/components/common/item-selector/item-selector.js
@@ -28,7 +28,7 @@ import styled from 'styled-components';
import Accessor from './accessor';
import ChickletedInput from './chickleted-input';
import Typeahead from './typeahead';
-import {Delete} from 'components/common/icons';
+import {Delete, ArrowDown} from 'components/common/icons';
import DropdownList, {ListItem} from './dropdown-list';
import {toArray} from 'utils/utils';
@@ -75,9 +75,14 @@ const DropdownSelectValue = styled.span`
}
`;
-const DropdownSelectErase = styled.div`
- margin-left: 6px;
+const DropdownSelectActionRight = styled.div`
+ margin-right: 6px;
display: flex;
+ color: ${props => props.theme.subtextColor};
+
+ :hover {
+ color: ${props => props.theme.textColor};
+ }
`;
const DropdownWrapper = styled.div`
@@ -109,6 +114,7 @@ class ItemSelector extends Component {
// optional properties
fixedOptions: PropTypes.arrayOf(PropTypes.any),
erasable: PropTypes.bool,
+ showArrow: PropTypes.bool,
displayOption: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
getOptionValue: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
filterOption: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
@@ -129,6 +135,7 @@ class ItemSelector extends Component {
static defaultProps = {
erasable: false,
+ showArrow: false,
placement: 'bottom',
selectedItems: [],
displayOption: null,
@@ -307,9 +314,13 @@ class ItemSelector extends Component {
)}
</DropdownSelectValue>
{this.props.erasable && hasValue ? (
- <DropdownSelectErase>
+ <DropdownSelectActionRight>
<Delete height="12px" onClick={this._onErase} />
- </DropdownSelectErase>
+ </DropdownSelectActionRight>
+ ) : this.props.showArrow ? (
+ <DropdownSelectActionRight>
+ <ArrowDown height="14px" onClick={this._showTypeahead} />
+ </DropdownSelectActionRight>
) : null}
</StyledDropdownSelect>
)}
diff --git a/src/components/common/item-selector/typeahead.js b/src/components/common/item-selector/typeahead.js
index 7a02085e6..34dc40b04 100644
--- a/src/components/common/item-selector/typeahead.js
+++ b/src/components/common/item-selector/typeahead.js
@@ -42,7 +42,8 @@ const DEFAULT_CLASS = 'typeahead';
const TypeaheadWrapper = styled.div`
display: flex;
flex-direction: column;
- background-color: ${props => props.theme.dropdownListBgd};
+ background-color: ${props =>
+ props.light ? props.theme.dropdownListBgdLT : props.theme.dropdownListBgd};
box-shadow: ${props => props.theme.dropdownListShadow};
:focus {
@@ -50,18 +51,23 @@ const TypeaheadWrapper = styled.div`
}
`;
-const InputBox = styled.div`
+const InputBox = styled.div.attrs({
+ className: 'typeahead__input_box'
+})`
padding: 8px;
`;
const TypeaheadInput = styled.input`
- ${props => props.theme.secondaryInput} :hover {
+ ${props => (props.light ? props.theme.inputLT : props.theme.secondaryInput)} :hover {
cursor: pointer;
- background-color: ${props => props.theme.secondaryInputBgd};
+ background-color: ${props =>
+ props.light ? props.theme.selectBackgroundLT : props.theme.secondaryInputBgd};
}
`;
-const InputIcon = styled.div`
+const InputIcon = styled.div.attrs({
+ className: 'typeahead__input_icon'
+})`
position: absolute;
right: 15px;
top: 14px;
@@ -171,6 +177,7 @@ class Typeahead extends Component {
defaultClassNames: true,
customListComponent: DropdownList,
customListItemComponent: ListItem,
+ inputIcon: Search,
customListHeaderComponent: null,
showOptionsWhenEmpty: true,
searchable: true,
@@ -460,6 +467,7 @@ class Typeahead extends Component {
onKeyPress={this.props.onKeyPress}
onKeyUp={this.props.onKeyUp}
onFocus={this._onFocus}
+ light={this.props.light}
>
{this._renderHiddenInput()}
{this.props.searchable ? (
@@ -474,9 +482,10 @@ class Typeahead extends Component {
value={this.state.entryValue}
onChange={this._onChange}
onBlur={this._onBlur}
+ light={this.props.light}
/>
<InputIcon>
- <Search height="18px" />
+ <this.props.inputIcon height="18px" />
</InputIcon>
</InputBox>
) : null}
diff --git a/src/components/common/map-layer-selector.js b/src/components/common/map-layer-selector.js
index af4e71494..9af39cd66 100644
--- a/src/components/common/map-layer-selector.js
+++ b/src/components/common/map-layer-selector.js
@@ -21,7 +21,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
-import Switch from 'components/common/switch';
+// import Switch from 'components/common/switch';
+import Checkbox from 'components/common/checkbox';
import {generateHashId} from '../../utils/utils';
const propTypes = {
@@ -42,7 +43,8 @@ const MapLayerSelector = ({layers, onMapToggleLayer}) => (
<MapLayerSelect className="map-layer-selector">
{layers.map((layer, index) => (
<div key={layer.id} className="map-layer-selector__item">
- <Switch
+ <Checkbox
+ type="radio"
checked={layer.isVisible}
id={`${layer.id}-toggle-${generateHashId(4)}`}
label={layer.name}
diff --git a/src/components/index.js b/src/components/index.js
index d10cdce25..5d4b468db 100644
--- a/src/components/index.js
+++ b/src/components/index.js
@@ -136,20 +136,22 @@ export {default as FileUploadFactory, FileUpload} from './common/file-uploader/f
export {default as DatasetLabel} from './common/dataset-label';
export {default as ItemSelector} from './common/item-selector/item-selector';
export {default as Typeahead} from './common/item-selector/typeahead';
+export {default as DropdownList} from './common/item-selector/dropdown-list';
export {default as FieldSelectorFactory} from './common/field-selector';
export {default as Modal, ModalFooter, ModalTitle} from './common/modal';
export {default as AppLogo} from './common/logo';
export {default as Switch} from './common/switch';
+export {default as Checkbox} from 'components/common/checkbox';
export {default as LoadingSpinner} from './common/loading-spinner';
export {default as LoadingDialog} from './modals/loading-dialog';
export {default as FieldTokenFactory} from './common/field-token';
export {default as Portaled} from './common/portaled';
-export {default as DropdownList} from './common/item-selector/dropdown-list';
export {default as ProgressBar} from './common/progress-bar';
export {default as FileUploadProgress} from './common/file-uploader/file-upload-progress';
export {default as Slider} from './common/slider/slider';
export {DatasetSquare} from './common/styled-components';
export {default as ActionPanel, ActionPanelItem} from 'components/common/action-panel';
+
// side pane components
export {default as LayerTypeSelector} from './side-panel/layer-panel/layer-type-selector';
export {ConfigGroupCollapsibleContent} from './side-panel/layer-panel/layer-config-group';
diff --git a/src/components/modals/data-table-modal.js b/src/components/modals/data-table-modal.js
index a2fcdc3ee..f6282bff5 100644
--- a/src/components/modals/data-table-modal.js
+++ b/src/components/modals/data-table-modal.js
@@ -148,11 +148,10 @@ function DataTableModalFactory(DataTable) {
});
render() {
- const {datasets, dataId, showDatasetTable} = this.props;
+ const {datasets, dataId, showDatasetTable, showTab} = this.props;
if (!datasets || !dataId) {
return null;
}
-
const activeDataset = datasets[dataId];
const columns = this.columns(this.props);
const colMeta = this.colMeta(this.props);
@@ -162,11 +161,13 @@ function DataTableModalFactory(DataTable) {
<StyledModal className="dataset-modal" id="dataset-modal">
<CanvasHack />
<TableContainer>
- <DatasetTabs
- activeDataset={activeDataset}
- datasets={datasets}
- showDatasetTable={showDatasetTable}
- />
+ {showTab ? (
+ <DatasetTabs
+ activeDataset={activeDataset}
+ datasets={datasets}
+ showDatasetTable={showDatasetTable}
+ />
+ ) : null}
{datasets[dataId] ? (
<DataTable
key={dataId}
@@ -188,7 +189,9 @@ function DataTableModalFactory(DataTable) {
);
}
}
-
+ DataTableModal.defaultProps = {
+ showTab: true
+ };
return withTheme(DataTableModal);
}
diff --git a/src/styles/base.js b/src/styles/base.js
index 0c007f5da..5db2c2593 100644
--- a/src/styles/base.js
+++ b/src/styles/base.js
@@ -206,6 +206,13 @@ export const checkboxBorderColorLT = selectBorderColorLT;
export const checkboxBoxBgd = 'white';
export const checkboxBoxBgdChecked = primaryBtnBgd;
+// Radio
+export const radioRadius = 8;
+export const radioBorderRadius = 100;
+export const radioBorderColor = 'transparent';
+export const radioButtonRadius = 4;
+export const radioButtonBgdColor = switchBtnBgdActive;
+
// Side Panel
export const sidePanelHeaderBg = '#29323C';
export const sidePanelHeaderBorder = 'transparent';
@@ -709,6 +716,35 @@ const inputCheckbox = css`
}
`;
+const inputRadio = css`
+ ${props => props.theme.inputCheckbox}
+ padding-left: ${props => props.theme.radioRadius * 2 + 8}px;
+ margin-bottom: 0;
+ margin-left: 0;
+ line-height: ${props => props.theme.radioRadius * 2}px;
+ cursor: pointer;
+
+ :before {
+ ${props => props.theme.checkboxBox}
+ width: ${props => props.theme.radioRadius * 2}px;
+ height: ${props => props.theme.radioRadius * 2}px;
+ border-radius: ${props => props.theme.radioBorderRadius}px;
+ background-color: ${props => props.theme.switchTrackBgd};
+ border-color: ${props => props.theme.radioBorderColor};
+ }
+
+ :after {
+ top: ${props => props.theme.radioRadius - props.theme.radioButtonRadius}px;
+ left: ${props => props.theme.radioRadius - props.theme.radioButtonRadius}px;
+ display: table;
+ width: ${props => props.theme.radioButtonRadius * 2}px;
+ height: ${props => props.theme.radioButtonRadius * 2}px;
+ border-radius: ${props => props.theme.radioButtonRadius * 2}px;
+ border: 0;
+ background-color: ${props => props.theme.radioButtonBgdColor};
+ }
+`;
+
const secondarySwitch = css`
${props => props.theme.inputSwitch}
@@ -1018,6 +1054,7 @@ export const theme = {
switchTrack,
switchButton,
inputCheckbox,
+ inputRadio,
checkboxBox,
checkboxCheck,
@@ -1125,6 +1162,13 @@ export const theme = {
checkboxBoxBgd,
checkboxBoxBgdChecked,
+ // Radio
+ radioRadius,
+ radioBorderRadius,
+ radioBorderColor,
+ radioButtonRadius,
+ radioButtonBgdColor,
+
// Button
btnFontFamily,
primaryBtnBgd,
diff --git a/src/utils/dataset-utils.d.ts b/src/utils/dataset-utils.d.ts
index cf6309b79..9bd125a5f 100644
--- a/src/utils/dataset-utils.d.ts
+++ b/src/utils/dataset-utils.d.ts
@@ -13,4 +13,6 @@ export function sortDatasetByColumn(
dataset: Dataset,
column: string,
mode?: string
-): Dataset
\ No newline at end of file
+): Dataset
+
+export const datasetColorMaker: Generator<RGBColor>;
diff --git a/src/utils/index.js b/src/utils/index.js
index 7694969aa..f9f27ef72 100644
--- a/src/utils/index.js
+++ b/src/utils/index.js
@@ -20,7 +20,7 @@
// UTILS
export {maybeToDate, roundValToStep, timeToUnixMilli} from './data-utils';
-export {findPointFieldPairs, createNewDataEntry} from './dataset-utils';
+export {findPointFieldPairs, createNewDataEntry, datasetColorMaker} from './dataset-utils';
export {hexToRgb} from './color-utils';
export {errorNotification} from './notifications-utils';
export {dataURItoBlob} from './export-utils';