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: ui tweak to make badge position fixed #232

Merged
merged 4 commits into from
Dec 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ exports[`BottomBarItem > should render the component as HTMLAnchorElement with a
<DocumentFragment>
<a
aria-current="page"
class="mocked-styled-3 el-anchor-bottom-bar-item-container"
class="mocked-styled-4 el-anchor-bottom-bar-item-container"
href="#"
>
<div
class="mocked-styled-0 el-bottom-bar-item-icon"
role="presentation"
class="mocked-styled-2 el-bottom-bar-item-content"
>
<span>
icon
</span>
<div
class="mocked-styled-0 el-bottom-bar-item-icon"
role="presentation"
>
<span>
icon
</span>
</div>
</div>
<span
class="mocked-styled-1 el-bottom-bar-item-label"
Expand All @@ -27,16 +31,20 @@ exports[`BottomBarItem > should render the component as HTMLAnchorElement with a
exports[`BottomBarItem > should render the component as HTMLAnchorElement with default state 1`] = `
<DocumentFragment>
<a
class="mocked-styled-3 el-anchor-bottom-bar-item-container"
class="mocked-styled-4 el-anchor-bottom-bar-item-container"
href="#"
>
<div
class="mocked-styled-0 el-bottom-bar-item-icon"
role="presentation"
class="mocked-styled-2 el-bottom-bar-item-content"
>
<span>
icon
</span>
<div
class="mocked-styled-0 el-bottom-bar-item-icon"
role="presentation"
>
<span>
icon
</span>
</div>
</div>
<span
class="mocked-styled-1 el-bottom-bar-item-label"
Expand All @@ -51,15 +59,19 @@ exports[`BottomBarItem > should render the component as HTMLButtonElement with a
<DocumentFragment>
<button
aria-current="true"
class="mocked-styled-4 el-button-bottom-bar-item-container"
class="mocked-styled-5 el-button-bottom-bar-item-container"
>
<div
class="mocked-styled-0 el-bottom-bar-item-icon"
role="presentation"
class="mocked-styled-2 el-bottom-bar-item-content"
>
<span>
icon
</span>
<div
class="mocked-styled-0 el-bottom-bar-item-icon"
role="presentation"
>
<span>
icon
</span>
</div>
</div>
<span
class="mocked-styled-1 el-bottom-bar-item-label"
Expand All @@ -74,24 +86,28 @@ exports[`BottomBarItem > should render the component as HTMLButtonElement with b
<DocumentFragment>
<button
aria-current="true"
class="mocked-styled-4 el-button-bottom-bar-item-container"
class="mocked-styled-5 el-button-bottom-bar-item-container"
>
<div
class="mocked-styled-0 el-bottom-bar-item-icon"
role="presentation"
class="mocked-styled-2 el-bottom-bar-item-content"
>
<span>
icon
</span>
<div
class="mocked-styled-0 el-bottom-bar-item-icon"
role="presentation"
>
<span>
icon
</span>
</div>
<span
class="mocked-styled-3 el-bottom-bar-item-badge"
/>
</div>
<span
class="mocked-styled-1 el-bottom-bar-item-label"
>
Label
</span>
<span
class="mocked-styled-2 el-bottom-bar-item-badge"
/>
</button>
</DocumentFragment>
`;
Expand All @@ -100,15 +116,19 @@ exports[`BottomBarItem > should render the component as HTMLButtonElement with d
<DocumentFragment>
<button
aria-current="true"
class="mocked-styled-4 el-button-bottom-bar-item-container"
class="mocked-styled-5 el-button-bottom-bar-item-container"
>
<div
class="mocked-styled-0 el-bottom-bar-item-icon"
role="presentation"
class="mocked-styled-2 el-bottom-bar-item-content"
>
<span>
icon
</span>
<div
class="mocked-styled-0 el-bottom-bar-item-icon"
role="presentation"
>
<span>
icon
</span>
</div>
</div>
<span
class="mocked-styled-1 el-bottom-bar-item-label"
Expand Down
15 changes: 10 additions & 5 deletions src/components/bottom-bar-item/bottom-bar-item.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Icon } from '../icon'
import {
ElAnchorBottomBarItemContainer,
ElBottomBarItemBadge,
ElBottomBarItemContent,
ElBottomBarItemIcon,
ElBottomBarItemLabel,
ElButtonBottomBarItemContainer,
Expand Down Expand Up @@ -96,9 +97,11 @@ export const StyleAnchorUsage: Story = {
</ElAnchorBottomBarItemContainer>

<ElAnchorBottomBarItemContainer href={args.href} aria-current={undefined} className="el-mx5">
<ElBottomBarItemIcon>{args?.icon}</ElBottomBarItemIcon>
<ElBottomBarItemContent>
<ElBottomBarItemIcon>{args?.icon}</ElBottomBarItemIcon>
<ElBottomBarItemBadge />
</ElBottomBarItemContent>
<ElBottomBarItemLabel>{args?.children}</ElBottomBarItemLabel>
<ElBottomBarItemBadge role="status" />
</ElAnchorBottomBarItemContainer>
</FlexContainer>
)
Expand All @@ -124,9 +127,11 @@ export const StyleButtonUsage: Story = {
</ElButtonBottomBarItemContainer>

<ElButtonBottomBarItemContainer onClick={action('handleClick')} aria-current={undefined} className="el-mx5">
<ElBottomBarItemIcon>{args?.icon}</ElBottomBarItemIcon>
<ElBottomBarItemLabel>{args?.children}</ElBottomBarItemLabel>
<ElBottomBarItemBadge role="status" />
<ElBottomBarItemContent>
<ElBottomBarItemIcon>{args?.icon}</ElBottomBarItemIcon>
<ElBottomBarItemBadge />
</ElBottomBarItemContent>
<ElBottomBarItemLabel>{args?.children}</ElBottomBarItemLabel>{' '}
</ElButtonBottomBarItemContainer>
</FlexContainer>
)
Expand Down
13 changes: 9 additions & 4 deletions src/components/bottom-bar-item/bottom-bar-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { AnchorHTMLAttributes, ButtonHTMLAttributes, FC, MouseEventHandler,
import {
ElAnchorBottomBarItemContainer,
ElBottomBarItemBadge,
ElBottomBarItemContent,
ElBottomBarItemIcon,
ElBottomBarItemLabel,
ElButtonBottomBarItemContainer,
Expand Down Expand Up @@ -68,19 +69,23 @@ export const BottomBarItem: FC<BottomBarItemProps> = (props) => {

return (
<ElButtonBottomBarItemContainer {...rest} aria-current={isActive ? 'true' : undefined}>
<ElBottomBarItemIcon role="presentation">{icon}</ElBottomBarItemIcon>
<ElBottomBarItemContent>
<ElBottomBarItemIcon role="presentation">{icon}</ElBottomBarItemIcon>
{hasBadge && <ElBottomBarItemBadge />}
</ElBottomBarItemContent>
<ElBottomBarItemLabel>{children}</ElBottomBarItemLabel>
{hasBadge && <ElBottomBarItemBadge />}
</ElButtonBottomBarItemContainer>
)
} else {
const { isActive, icon, hasBadge, children, ...rest } = props ?? {}

return (
<ElAnchorBottomBarItemContainer {...rest} aria-current={isActive ? 'page' : undefined}>
<ElBottomBarItemIcon role="presentation">{icon}</ElBottomBarItemIcon>
<ElBottomBarItemContent>
<ElBottomBarItemIcon role="presentation">{icon}</ElBottomBarItemIcon>
{hasBadge && <ElBottomBarItemBadge />}
</ElBottomBarItemContent>
<ElBottomBarItemLabel>{children}</ElBottomBarItemLabel>
{hasBadge && <ElBottomBarItemBadge />}
</ElAnchorBottomBarItemContainer>
)
}
Expand Down
13 changes: 9 additions & 4 deletions src/components/bottom-bar-item/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ export const ElBottomBarItemLabel = styled.span`
const baseStyles = `
background-color: var(--fill-white, white);
outline: none;
width: 44px;
width: 44px;
border: var(--border-none, 0);
display: flex;
cursor: pointer;
padding: var(--space-half, 2px) var(--space-none, 0px);
padding: var(--space-half, 2px) var(--space-none, 0px);
flex-direction: column;
align-items: center;
gap: var(--space-half, 2px);
position: relative;
flex: 1 0 0;

color: var(--icon-secondary, #607890);

Expand All @@ -39,10 +40,14 @@ const baseStyles = `
}
`

export const ElBottomBarItemContent = styled.div`
position: relative;
`

export const ElBottomBarItemBadge = styled.span`
position: absolute;
top: 1px;
right: 6px;
top: -3px;
right: -3px;
width: var(--size-2, 8px);
height: var(--size-2, 8px);
background-color: var(--icon-error, #f01830);
Expand Down
Loading