Skip to content

Commit

Permalink
Merge pull request kubesphere#154 from chenz24/hotfix
Browse files Browse the repository at this point in the history
fix: improve entity expand feature.
  • Loading branch information
chenz24 authored Mar 29, 2022
2 parents c0e503c + dcdc5dc commit a704bd7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-bats-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kubed/components': patch
---

1. fix: improve entity expand feature.
13 changes: 12 additions & 1 deletion packages/components/src/Entity/Entity.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ export const EntityExpand = () => {
width: 100%;
height: 300px;
`;

const onCardClick = (e) => {
e.stopPropagation();
};

const expandContent = (
<Card sectionTitle="容器" className="entity-card" padding={0}>
<Card sectionTitle="容器" className="entity-card" padding={0} onClick={onCardClick}>
<Entity>
<Field avatar={Avatar} label="镜像: rocksdb" value="kubespheredev/ks-console:master" />
<Field label="存储卷" value="rocksdbpvc" />
Expand All @@ -78,6 +83,12 @@ export const EntityExpand = () => {
<Field label="容量" value="1Gi" width={100} />
<Field label="访问模式" value="ReadWriteOnce" />
</Entity>
<Entity expandable hoverable expandContent={expandContent} className="test-classname">
<Field avatar={Avatar} label="存储类型: rocksdb" value={<a href="/">rocksdbpvc</a>} />
<Field label="存储卷" value="rocksdbpvc" />
<Field label="容量" value="1Gi" width={100} />
<Field label="访问模式" value="ReadWriteOnce" />
</Entity>
</Wrapper>
);
};
Expand Down
39 changes: 10 additions & 29 deletions packages/components/src/Entity/Entity.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react';
import styled, { css } from 'styled-components';
import cx from 'classnames';
import { useToggle } from '@kubed/hooks';
import { Dropdown } from '../Dropdown/Dropdown';
import { Dropdown, DropdownProps } from '../Dropdown/Dropdown';
import { Field } from './Field';
import { DefaultProps, KubedTheme } from '../theme';
import forwardRef from '../utils/forwardRef';
Expand Down Expand Up @@ -41,7 +39,7 @@ const EntityWrapper = styled('div')<EntityProps>`
cursor: ${({ expandable }) => (expandable ? 'pointer' : null)};
&:hover,
&.is-expand {
&[aria-expanded='true'] {
${({ hoverable, theme }) => getHoverStyle(hoverable, theme)};
}
`;
Expand Down Expand Up @@ -87,6 +85,9 @@ export interface EntityProps extends DefaultProps {

/** Gap between children */
gap?: number;

/** Props of expand */
expandProps?: Omit<DropdownProps, 'children'>;
}

export const Entity = forwardRef<EntityProps, 'div'>(
Expand All @@ -99,19 +100,11 @@ export const Entity = forwardRef<EntityProps, 'div'>(
bordered = true,
expandable = false,
expandContent,
expandProps,
...rest
},
ref
) => {
const [expand, setExpand] = useToggle(false, [true, false]);

const handleExpand = (e) => {
e.stopPropagation();
if (expandable) {
setExpand(!expand);
}
};

if (expandable) {
return (
<Wrapper>
Expand All @@ -123,15 +116,10 @@ export const Entity = forwardRef<EntityProps, 'div'>(
className="entity-dropdown"
maxWidth="100%"
offset={[0, -3]}
placement="bottom"
{...expandProps}
>
<EntityWrapper
ref={ref}
bordered={bordered}
expandable={expandable}
onClick={handleExpand}
className={cx({ 'is-expand': expandable && expand }, className)}
{...rest}
>
<EntityWrapper ref={ref} bordered={bordered} expandable={expandable} {...rest}>
<EntityContainer $gap={gap} className="entity-main">
{children}
</EntityContainer>
Expand All @@ -143,14 +131,7 @@ export const Entity = forwardRef<EntityProps, 'div'>(
}

return (
<EntityWrapper
ref={ref}
bordered={bordered}
expandable={expandable}
onClick={handleExpand}
className={cx({ 'is-expand': expandable && expand }, className)}
{...rest}
>
<EntityWrapper ref={ref} bordered={bordered} expandable={expandable} {...rest}>
<EntityContainer $gap={gap} className="entity-main">
{children}
</EntityContainer>
Expand Down

0 comments on commit a704bd7

Please sign in to comment.