-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Includes opacity and dataset remove button
- Loading branch information
1 parent
fe1ebf7
commit 0d3d652
Showing
8 changed files
with
280 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import React from 'react'; | ||
import { PrimitiveAtom, useAtomValue, useSetAtom } from 'jotai'; | ||
import 'react-range-slider-input/dist/style.css'; | ||
import styled from 'styled-components'; | ||
import { glsp, themeVal } from '@devseed-ui/theme-provider'; | ||
import { Dropdown, DropMenu, DropTitle } from '@devseed-ui/dropdown'; | ||
import { Button } from '@devseed-ui/button'; | ||
import { CollecticonCog, CollecticonTrashBin } from '@devseed-ui/collecticons'; | ||
import { Overline } from '@devseed-ui/typography'; | ||
|
||
import { useTimelineDatasetSettings } from './hooks'; | ||
import { TimelineDataset } from './constants'; | ||
import { timelineDatasetsAtom } from './atoms'; | ||
|
||
import DropMenuItemButton from '$styles/drop-menu-item-button'; | ||
import { SliderInput, SliderInputProps } from '$styles/range-slider'; | ||
|
||
interface DatasetOptionsProps { | ||
datasetAtom: PrimitiveAtom<TimelineDataset>; | ||
} | ||
|
||
export default function DatasetOptions(props: DatasetOptionsProps) { | ||
const { datasetAtom } = props; | ||
|
||
const setDatasets = useSetAtom(timelineDatasetsAtom); | ||
const dataset = useAtomValue(datasetAtom); | ||
const [getSettings, setSetting] = useTimelineDatasetSettings(datasetAtom); | ||
|
||
const opacity = (getSettings('opacity') ?? 100) as number; | ||
|
||
return ( | ||
<Dropdown | ||
alignment='right' | ||
triggerElement={(props) => ( | ||
<Button variation='base-text' size='small' fitting='skinny' {...props}> | ||
<CollecticonCog meaningful title='View dataset options' /> | ||
</Button> | ||
)} | ||
> | ||
<DropTitle>View options</DropTitle> | ||
<DropMenu> | ||
<li> | ||
<OpacityControl | ||
value={opacity} | ||
onInput={(v) => setSetting('opacity', v)} | ||
/> | ||
</li> | ||
</DropMenu> | ||
<DropMenu> | ||
<li> | ||
<DropMenuItemButton | ||
variation='danger' | ||
onClick={() => { | ||
setDatasets((datasets) => | ||
datasets.filter((d) => d.data.id !== dataset.data.id) | ||
); | ||
}} | ||
> | ||
<CollecticonTrashBin /> Remove dataset | ||
</DropMenuItemButton> | ||
</li> | ||
</DropMenu> | ||
</Dropdown> | ||
); | ||
} | ||
|
||
const OpacityControlWrapper = styled.div` | ||
padding: ${glsp(0.5, 1)}; | ||
display: flex; | ||
flex-flow: column; | ||
gap: ${glsp(0.25)}; | ||
`; | ||
|
||
const OpacityControlElements = styled.div` | ||
display: flex; | ||
gap: ${glsp(0.5)}; | ||
align-items: center; | ||
`; | ||
|
||
const OpacityValue = styled.span` | ||
font-size: 0.75rem; | ||
font-weight: ${themeVal('type.base.regular')}; | ||
color: ${themeVal('color.base-400')}; | ||
width: 2rem; | ||
text-align: right; | ||
`; | ||
|
||
function OpacityControl(props: SliderInputProps) { | ||
const { value, onInput } = props; | ||
|
||
return ( | ||
<OpacityControlWrapper> | ||
<Overline>Opacity</Overline> | ||
<OpacityControlElements> | ||
<SliderInput value={value} onInput={onInput} /> | ||
<OpacityValue>{value}</OpacityValue> | ||
</OpacityControlElements> | ||
</OpacityControlWrapper> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,52 @@ | ||
import styled, { css } from 'styled-components'; | ||
import { DropMenuItem } from '@devseed-ui/dropdown'; | ||
import { rgba, themeVal } from '@devseed-ui/theme-provider'; | ||
import { DropMenuItem, DropMenuItemProps } from '@devseed-ui/dropdown'; | ||
import { themeVal } from '@devseed-ui/theme-provider'; | ||
|
||
const rgbaFixed = rgba as any; | ||
interface DropMenuItemButtonProps extends DropMenuItemProps { | ||
variation?: | ||
| 'base' | ||
| 'primary' | ||
| 'secondary' | ||
| 'danger' | ||
| 'success' | ||
| 'warning' | ||
| 'info'; | ||
} | ||
|
||
const DropMenuItemButton = styled(DropMenuItem).attrs({ | ||
as: 'button', | ||
'data-dropdown': 'click.close' | ||
})` | ||
})<DropMenuItemButtonProps>` | ||
background: none; | ||
border: none; | ||
width: 100%; | ||
cursor: pointer; | ||
text-align: left; | ||
${({ active }) => | ||
active && | ||
css` | ||
&, | ||
&:visited { | ||
background-color: ${rgbaFixed(themeVal('color.link'), 0.08)}; | ||
} | ||
`} | ||
${(props) => renderVariation(props)} | ||
`; | ||
|
||
export default DropMenuItemButton; | ||
|
||
function renderVariation(props: DropMenuItemButtonProps) { | ||
const { variation = 'base', active } = props; | ||
|
||
return css` | ||
color: ${themeVal(`color.${variation}`)}; | ||
&:hover { | ||
color: ${themeVal(`color.${variation}`)}; | ||
background-color: ${themeVal(`color.${variation}-50a`)}; | ||
} | ||
/* Print & when prop is passed */ | ||
${active && '&,'} | ||
&.active { | ||
background-color: ${themeVal(`color.${variation}-100a`)}; | ||
} | ||
&:focus-visible { | ||
outline-color: ${themeVal(`color.${variation}-200a`)}; | ||
} | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import RangeSlider from 'react-range-slider-input'; | ||
import 'react-range-slider-input/dist/style.css'; | ||
|
||
import { themeVal } from '@devseed-ui/theme-provider'; | ||
|
||
export interface RangeSliderInputProps { | ||
id?: string; | ||
className?: string; | ||
min?: number; | ||
max?: number; | ||
step?: number; | ||
defaultValue?: [number, number]; | ||
value: [number, number]; | ||
onInput: (v: [number, number]) => void; | ||
// onThumbDragStart; | ||
// onThumbDragEnd; | ||
// onRangeDragStart; | ||
// onRangeDragEnd; | ||
disabled?: boolean; | ||
rangeSlideDisabled?: boolean; | ||
thumbsDisabled?: [boolean, boolean]; | ||
orientation?: 'horizontal' | 'vertical'; | ||
} | ||
|
||
export const RangeSliderInput = styled(RangeSlider)<RangeSliderInputProps>` | ||
&& { | ||
background: ${themeVal('color.base-200')}; | ||
border-radius: ${themeVal('shape.rounded')}; | ||
.range-slider__range { | ||
border-radius: ${themeVal('shape.rounded')}; | ||
background: ${themeVal('color.primary')}; | ||
} | ||
.range-slider__thumb { | ||
transition: background 160ms ease-in-out; | ||
background: ${themeVal('color.surface')}; | ||
box-shadow: ${themeVal('boxShadow.elevationD')}; | ||
width: 1.25rem; | ||
height: 1.25rem; | ||
&:hover { | ||
background: ${themeVal('color.base-50')}; | ||
} | ||
} | ||
.range-slider__thumb[data-lower] { | ||
width: 0; | ||
} | ||
} | ||
`; | ||
|
||
export interface SliderInputProps | ||
extends Omit<RangeSliderInputProps, 'value' | 'onInput'> { | ||
value: number; | ||
onInput: (v: number) => void; | ||
} | ||
|
||
export function SliderInput(props: SliderInputProps) { | ||
const { value, onInput, ...rest } = props; | ||
|
||
return ( | ||
<RangeSliderInput | ||
{...rest} | ||
value={[0, value]} | ||
onInput={(v) => onInput(v[1])} | ||
thumbsDisabled={[true, false]} | ||
rangeSlideDisabled | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters