-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SelectableCard): gallery variant and some improvements
- Loading branch information
1 parent
7877a0d
commit b10b3e4
Showing
16 changed files
with
422 additions
and
131 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
87 changes: 0 additions & 87 deletions
87
...ages/react-components/src/components/SelectableCard/SelectableCard.stories.components.tsx
This file was deleted.
Oops, something went wrong.
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
94 changes: 94 additions & 0 deletions
94
...ents/SelectableCard/components/GallerySelectableCard/GallerySelectableCard.components.tsx
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,94 @@ | ||
import * as React from 'react'; | ||
|
||
import { | ||
Palette, | ||
Building, | ||
AccountCircle, | ||
Group, | ||
} from '@livechat/design-system-icons'; | ||
|
||
import { Icon } from '../../../Icon'; | ||
|
||
import { GallerySelectableCard } from './GallerySelectableCard'; | ||
|
||
const ICONS = [Palette, Building, AccountCircle, Group]; | ||
|
||
interface IRadioCardsProps { | ||
withIcon?: boolean; | ||
withCustomElement?: boolean; | ||
} | ||
|
||
const getComponent = ( | ||
index: number, | ||
isSelected: boolean, | ||
setSelectedIndex: (index: number) => void, | ||
withIcon: boolean | undefined, | ||
withCustomElement: boolean | undefined, | ||
type: 'radio' | 'checkbox' | ||
) => ( | ||
<GallerySelectableCard | ||
key={index} | ||
label={`Card ${index + 1}`} | ||
selectionType={type} | ||
isSelected={isSelected} | ||
onClick={() => setSelectedIndex(index)} | ||
{...(withIcon && { icon: <Icon size="xlarge" source={ICONS[index]} /> })} | ||
{...(withCustomElement && { | ||
customElement: ( | ||
<div className="gallery-custom-element"> | ||
<Icon size="small" source={ICONS[index]} /> | ||
<div>{`Custom element ${index + 1}`}</div> | ||
</div> | ||
), | ||
})} | ||
/> | ||
); | ||
|
||
export const RadioCards: React.FC<IRadioCardsProps> = ({ | ||
withIcon, | ||
withCustomElement, | ||
}) => { | ||
const [selectedIndex, setSelectedIndex] = React.useState<number>(0); | ||
|
||
return [...Array(4)].map((_, index) => | ||
getComponent( | ||
index, | ||
selectedIndex === index, | ||
setSelectedIndex, | ||
withIcon, | ||
withCustomElement, | ||
'radio' | ||
) | ||
); | ||
}; | ||
|
||
interface ICheckboxCardsProps { | ||
withIcon?: boolean; | ||
withCustomElement?: boolean; | ||
} | ||
|
||
export const CheckboxCards: React.FC<ICheckboxCardsProps> = ({ | ||
withIcon, | ||
withCustomElement, | ||
}) => { | ||
const [selectedIndex, setSelectedIndex] = React.useState<number[]>([]); | ||
|
||
const handleCardClick = (index: number) => { | ||
if (selectedIndex.includes(index)) { | ||
setSelectedIndex(selectedIndex.filter((selected) => selected !== index)); | ||
} else { | ||
setSelectedIndex([...selectedIndex, index]); | ||
} | ||
}; | ||
|
||
return [...Array(4)].map((_, index) => | ||
getComponent( | ||
index, | ||
selectedIndex.includes(index), | ||
handleCardClick, | ||
withIcon, | ||
withCustomElement, | ||
'checkbox' | ||
) | ||
); | ||
}; |
17 changes: 17 additions & 0 deletions
17
...ponents/SelectableCard/components/GallerySelectableCard/GallerySelectableCard.module.scss
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,17 @@ | ||
$base-class: 'gallery-selectable-card'; | ||
|
||
.#{$base-class} { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
min-width: 60px; | ||
min-height: 72px; | ||
|
||
&__label { | ||
position: absolute; | ||
top: 100%; | ||
margin-top: var(--spacing-1); | ||
text-align: center; | ||
color: var(--content-basic-secondary); | ||
} | ||
} |
Oops, something went wrong.