Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(carousel): add halfControls property #19

Merged
merged 1 commit into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/carousel/src/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Screen = styled.div(
layout
)

export const Carousel = ({ children, disableButton = false, step = 1 }) => {
export const Carousel = ({ children, disableButton = false, step = 1, halfControls }) => {
const [enableTransition, setEnableTransition] = useState(true)
const [innerWidth, setInnerWidth] = useState(null)
const [fullWidth, setFullWidth] = useState(null)
Expand Down Expand Up @@ -168,7 +168,8 @@ export const Carousel = ({ children, disableButton = false, step = 1 }) => {
<SlideButton
onClick={() => handleClick('left')}
disabled={disableButton || buttonLeftDisabled}
direction='left'
direction={halfControls ? 'none' : 'left'}
halfControls={halfControls ? 'left' : 'none'}
>
<ArrowBackwardIcon width={24} height={24} />
</SlideButton>
Expand All @@ -185,7 +186,8 @@ export const Carousel = ({ children, disableButton = false, step = 1 }) => {
<SlideButton
onClick={() => handleClick('right')}
disabled={disableButton || buttonRightDisabled}
direction='right'
direction={halfControls ? 'none' : 'right'}
halfControls={halfControls ? 'right' : 'none'}
>
<ArrowForwardIcon width={24} height={24} />
</SlideButton>
Expand Down
14 changes: 12 additions & 2 deletions packages/carousel/src/SlideButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import { ifProp, switchProp } from 'styled-tools'

const disabled = ifProp('disabled', { display: 'none' })

const halfControls = switchProp('halfControls', {
left: {
left: '-33px',
},
right: {
right: '-33px',
},
})

const directions = switchProp('direction', () => ({
left: {
left: '20px',
Expand All @@ -21,7 +30,7 @@ export const SlideButton = styled.div<any>(
background: theme.colors.white,
boxSizing: 'border-box',
borderRadius: '50%',
boxShadow: theme.shadows.codgray,
boxShadow: theme.shadows.controls,
zIndex: 9,
display: 'flex',
alignItems: 'center',
Expand All @@ -39,5 +48,6 @@ export const SlideButton = styled.div<any>(
},
}),
disabled,
directions
directions,
halfControls
)