ISSUE-020 - Making a checkpoint in my work. SlotSelector written a little better. Animation work coming next.
This commit is contained in:
1 parent
35ca424dd6
commit
9b3ae2dae2
2 files changed
+18
-11
No files matched your search
@@ -26,24 +26,31 @@ export function SlotSelector({
|
|||||||
setPrefixMask(findPrefixCount(tempFormattedItems));
|
setPrefixMask(findPrefixCount(tempFormattedItems));
|
||||||
}, [items]);
|
}, [items]);
|
||||||
|
|
||||||
|
const getNextIndex = (i: number) => (i + 1) % items.length;
|
||||||
|
const getPreviousIndex = (i: number) => i - 1 >= 0 ? i - 1 : items.length - 1;
|
||||||
|
|
||||||
const onClick = () => {
|
const onClick = () => {
|
||||||
const nextIndex = (index + 1) % items.length;
|
const nextIndex = getNextIndex(index);
|
||||||
setIndex(nextIndex);
|
setIndex(nextIndex);
|
||||||
onChange(items[nextIndex]);
|
onChange(items[nextIndex]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getItem = (i: number) =>
|
||||||
|
formattedItems.length &&
|
||||||
|
removePrefix &&
|
||||||
|
formattedItems[0].length !== prefixMask ?
|
||||||
|
formattedItems[i].slice(prefixMask) :
|
||||||
|
formattedItems[i];
|
||||||
|
|
||||||
|
const currentItem = getItem(index);
|
||||||
|
const nextItem = getItem(getNextIndex(index));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SlotWindow
|
<SlotWindow
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
>
|
>
|
||||||
<SlotText>
|
<SlotText>{currentItem}</SlotText>
|
||||||
{formattedItems.length &&
|
<SlotText>{nextItem}</SlotText>
|
||||||
removePrefix && formattedItems[0].length !== prefixMask ?
|
|
||||||
formattedItems[index].slice(prefixMask)
|
|
||||||
:
|
|
||||||
formattedItems[index]
|
|
||||||
}
|
|
||||||
</SlotText>
|
|
||||||
</SlotWindow>
|
</SlotWindow>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -2,8 +2,7 @@ import styled from "styled-components";
|
|||||||
|
|
||||||
export const SlotWindow = styled.div`
|
export const SlotWindow = styled.div`
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 1.2em;
|
height: 1.7em;
|
||||||
height: 100%;
|
|
||||||
width: 200px;
|
width: 200px;
|
||||||
|
|
||||||
border-radius: 0.6em;
|
border-radius: 0.6em;
|
||||||
@@ -19,6 +18,7 @@ export const SlotWindow = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const SlotText = styled.span`
|
export const SlotText = styled.span`
|
||||||
|
display: block;
|
||||||
margin-left: .4em;
|
margin-left: .4em;
|
||||||
position: relative;
|
position: relative;
|
||||||
font-family: ${p => p.theme.fonts.f1Regular};
|
font-family: ${p => p.theme.fonts.f1Regular};
|
||||||
|
|||||||
Reference in new issue
Block a user