Skip to content

Commit

Permalink
Relate chevron to sorting option (#2782)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdegraaf authored Dec 12, 2023
1 parent fd5a703 commit a79f04c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('SortIcon', () => {
/>
)

expect(screen.getByTestId('chevron-up')).toBeInTheDocument()
expect(screen.getByTestId('chevron-down')).toBeInTheDocument()
})

it('should render a sort icon for address desc when its asc', () => {
Expand All @@ -71,7 +71,7 @@ describe('SortIcon', () => {
/>
)

expect(screen.getByTestId('chevron-down')).toBeInTheDocument()
expect(screen.getByTestId('chevron-up')).toBeInTheDocument()
})

it('should return null when there is no match between sortOption and selectedSortOption', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
// SPDX-License-Identifier: MPL-2.0
// Copyright (C) 2023 Gemeente Amsterdam
import { StyledChevronUp } from './styled'
import { SortOptions } from '../../contants'
import { Chevron } from './styled'
import type { SortOptions } from '../../contants'
import compareSortOptions from '../../utils'

const sortException = (sortOption: SortOptions) => {
return (
sortOption === SortOptions.CREATED_AT_ASC ||
sortOption === SortOptions.CREATED_AT_DESC ||
sortOption === SortOptions.ID_DESC ||
sortOption === SortOptions.ID_ASC
)
}
export default function SortIcon({
selectedSortOption,
sortOption,
Expand All @@ -31,19 +23,9 @@ export default function SortIcon({
)
return null

if (sortException(sortOption)) {
const rotateException = selectedSortOption?.startsWith('-')
return (
<StyledChevronUp
data-testid={rotateException ? 'chevron-down' : 'chevron-up'}
$rotated={rotateException}
/>
)
}

const rotate = !selectedSortOption?.startsWith('-')
const rotate = selectedSortOption?.startsWith('-')
return (
<StyledChevronUp
<Chevron
data-testid={rotate ? 'chevron-down' : 'chevron-up'}
$rotated={rotate}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChevronUp } from '@amsterdam/asc-assets'
import styled, { css } from 'styled-components'

export const StyledChevronUp = styled(ChevronUp)<{ $rotated: boolean }>`
export const Chevron = styled(ChevronUp)<{ $rotated: boolean }>`
transition: transform 0.25s;
${({ $rotated }) =>
$rotated &&
Expand Down

0 comments on commit a79f04c

Please sign in to comment.