-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
2,145 additions
and
2,502 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
assets/js/src/core/components/collapse/collapse.stories.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,79 @@ | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - Pimcore Open Core License (POCL) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL | ||
*/ | ||
|
||
import type { Meta, StoryObj } from '@storybook/react' | ||
import { Collapse, CollapseProps } from './collapse' | ||
import { Extra as CollapseItemDefault } from './item/collapse-item.stories' | ||
|
||
const config: Meta = { | ||
title: 'Components/Layout/Collapse/Collapse', | ||
component: Collapse, | ||
tags: ['autodocs'] | ||
} | ||
|
||
export default config | ||
|
||
export const _default: StoryObj<CollapseProps> = { | ||
args: { | ||
items: [ | ||
{ | ||
key: '1', | ||
...CollapseItemDefault.args, | ||
}, | ||
|
||
{ | ||
key: '2', | ||
...CollapseItemDefault.args, | ||
}, | ||
|
||
{ | ||
key: '3', | ||
...CollapseItemDefault.args, | ||
}, | ||
], | ||
} | ||
} | ||
|
||
export const Accordion: StoryObj<CollapseProps> = { | ||
args: { | ||
..._default.args, | ||
accordion: true, | ||
} | ||
} | ||
|
||
export const HandleUniqueItems: StoryObj<CollapseProps> = { | ||
args: { | ||
..._default.args, | ||
items: [ | ||
{ | ||
key: '1', | ||
...CollapseItemDefault.args, | ||
}, | ||
|
||
{ | ||
key: '2', | ||
...CollapseItemDefault.args, | ||
bordered: false, | ||
theme: 'primary', | ||
hasContentSeparator: false, | ||
}, | ||
|
||
{ | ||
key: '3', | ||
...CollapseItemDefault.args, | ||
}, | ||
], | ||
bordered: true, | ||
theme: 'success', | ||
} | ||
} |
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,96 @@ | ||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - Pimcore Open Core License (POCL) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL | ||
*/ | ||
|
||
import React, { useEffect, useState } from 'react' | ||
import { CollapseItem, type CollapseItemProps, type CollapseStyleProps } from './item/collapse-item' | ||
import { Space, type SpaceProps } from '../space/space' | ||
import cn from 'classnames' | ||
|
||
export interface ICollapseItem extends Omit<CollapseItemProps, 'active'> { | ||
key: string | ||
} | ||
|
||
export interface CollapseProps extends CollapseStyleProps { | ||
defaultActiveKeys?: string[] | ||
activeKeys?: string[] | ||
onChange?: CollapseItemProps['onChange'] | ||
items: ICollapseItem[] | ||
space?: SpaceProps | ||
accordion?: boolean | ||
className?: string | ||
} | ||
|
||
export const Collapse = ({ className, items, accordion, space, activeKeys, defaultActiveKeys, onChange, ...props }: CollapseProps): React.JSX.Element => { | ||
const [internalActiveKeys, setInternalActiveKeys] = useState<string[]>(activeKeys ?? defaultActiveKeys ?? []) | ||
|
||
useEffect(() => { | ||
if (activeKeys !== undefined) { | ||
setInternalActiveKeys(activeKeys) | ||
} | ||
}, [activeKeys]) | ||
|
||
const onItemChange = (item: ICollapseItem, keys: string[]): void => { | ||
const isItemActive = keys.includes('0') | ||
let newActiveKeys: string[] = [] | ||
|
||
if (accordion === true && isItemActive) { | ||
newActiveKeys = [item.key] | ||
} else if (isItemActive) { | ||
newActiveKeys = [...internalActiveKeys, item.key] | ||
} else { | ||
newActiveKeys = internalActiveKeys.filter((key) => key !== item.key) | ||
} | ||
|
||
if (activeKeys === undefined) { | ||
setInternalActiveKeys(newActiveKeys) | ||
} | ||
|
||
if (onChange !== undefined) { | ||
onChange(newActiveKeys) | ||
} | ||
} | ||
|
||
const preparedItems = items.map((item, index) => { | ||
return { | ||
...props, | ||
...item | ||
} | ||
}) | ||
|
||
const classnames = cn( | ||
'collapse', | ||
className, | ||
'w-full' | ||
) | ||
|
||
return ( | ||
<Space | ||
className={ classnames } | ||
direction="vertical" | ||
{ ...space } | ||
> | ||
{preparedItems.map((item) => { | ||
const { key, ...preparedItem } = item | ||
|
||
return ( | ||
<CollapseItem | ||
key={ key } | ||
{ ...preparedItem } | ||
active={ internalActiveKeys.includes(item.key) } | ||
onChange={ (keys) => { onItemChange(item, keys) } } | ||
/> | ||
) | ||
})} | ||
</Space> | ||
) | ||
} |
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
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
9 changes: 0 additions & 9 deletions
9
public/build/148fe31c-4497-4d59-a2a2-0258933183c4/entrypoints.json
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
public/build/148fe31c-4497-4d59-a2a2-0258933183c4/manifest.json
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.