Merge branch 'ISSUE-038' into ISSUE-032
This commit is contained in:
commit
8e4ac1243b
4 files changed
+21
-9
No files matched your search
@@ -6,10 +6,11 @@ import { SlotText, SlotWindow } from "./styles";
|
||||
|
||||
type SlotSelectorProps = {
|
||||
items: Array<string>,
|
||||
onChange: (value: string) => void,
|
||||
onChange: (index: number) => void,
|
||||
removePrefix?: boolean,
|
||||
formatter?: (value: string) => string,
|
||||
initialIndex?: number,
|
||||
disabled?: boolean,
|
||||
};
|
||||
export function SlotSelector({
|
||||
items,
|
||||
@@ -17,11 +18,16 @@ export function SlotSelector({
|
||||
removePrefix = false,
|
||||
formatter = (x) => x,
|
||||
initialIndex = 0,
|
||||
disabled = false,
|
||||
}: SlotSelectorProps) {
|
||||
const [index, setIndex] = useState(initialIndex);
|
||||
const [prefixMask, setPrefixMask] = useState(0);
|
||||
const [formattedItems, setFormattedItems] = useState<Array<string>>([]);
|
||||
|
||||
useEffect(() => {
|
||||
setIndex(initialIndex);
|
||||
}, [items]);
|
||||
|
||||
// useMemo makes these functions only run once when mounting. Not every re-render.
|
||||
useMemo(() => {
|
||||
const tempFormattedItems = items.map(item => formatter(item));
|
||||
@@ -30,9 +36,10 @@ export function SlotSelector({
|
||||
}, [items]);
|
||||
|
||||
const onClick = () => {
|
||||
if (disabled) return;
|
||||
const nextIndex = (index + 1) % items.length;
|
||||
setIndex(nextIndex);
|
||||
onChange(items[nextIndex]);
|
||||
onChange(nextIndex);
|
||||
};
|
||||
|
||||
const getItem = (i: number) =>
|
||||
@@ -56,7 +63,7 @@ export function SlotSelector({
|
||||
}, [index]);
|
||||
|
||||
return (
|
||||
<SlotWindow onClick={onClick}>
|
||||
<SlotWindow onClick={onClick} disabled={disabled}>
|
||||
{transitions((style, i) => (
|
||||
<SlotText as={animated.span} style={style}>{getItem(i)}</SlotText>
|
||||
))}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import styled from "styled-components";
|
||||
|
||||
export const SlotWindow = styled.div`
|
||||
type SlotWindowProps = {
|
||||
disabled: boolean,
|
||||
};
|
||||
export const SlotWindow = styled.div<SlotWindowProps>`
|
||||
position: relative;
|
||||
height: 1.5em;
|
||||
width: auto;
|
||||
|
||||
border-radius: 0.6em;
|
||||
background-color: white;
|
||||
background-color: ${({ disabled }) => disabled
|
||||
? p => p.theme.colors.lightGrey : "white"};
|
||||
box-shadow: inset 0 0 50px -50px ${p => p.theme.colors.darkGrey};
|
||||
border: 1px solid ${p => p.theme.colors.darkGrey};
|
||||
|
||||
|
||||
@@ -46,9 +46,10 @@ export function OverlayControl() {
|
||||
/>
|
||||
<SlotSelector
|
||||
items={overlayIds}
|
||||
onChange={(value) => dispatch(setCurrentOverlayId(value))}
|
||||
onChange={(index) => dispatch(setCurrentOverlayId(overlayIds[index]))}
|
||||
removePrefix
|
||||
formatter={(value) => value.replace(/(\.png)|(\.jpg)$/, "")}
|
||||
disabled={!visible}
|
||||
/>
|
||||
</Inline>
|
||||
<ProgressSlider
|
||||
|
||||
+3
-3
@@ -16,11 +16,11 @@ export function AngledFlagPrototypeControls() {
|
||||
const dispatch = useDispatch();
|
||||
const { prototypeState } = useSelector(workspaceSelector);
|
||||
|
||||
const onChange = (flag: "flagA" | "flagB") => (value: string) => {
|
||||
const onChange = (flag: "flagA" | "flagB") => (index: number) => {
|
||||
dispatch(setPrototypeState({
|
||||
angledFlag: {
|
||||
flagA: flag === "flagA" ? value : prototypeState?.angledFlag?.flagA ?? "GBR",
|
||||
flagB: flag === "flagB" ? value : prototypeState?.angledFlag?.flagB ?? "GBR",
|
||||
flagA: flag === "flagA" ? countries[index] : prototypeState?.angledFlag?.flagA ?? "GBR",
|
||||
flagB: flag === "flagB" ? countries[index] : prototypeState?.angledFlag?.flagB ?? "GBR",
|
||||
},
|
||||
}));
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user