-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from Mezzanine-UI/feat/react-anchor
'Anchor' component implemented
- Loading branch information
Showing
22 changed files
with
318 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ const preview: Preview = { | |
'Data Entry', | ||
'Data Display', | ||
'Feedback', | ||
'Others', | ||
], | ||
}, | ||
}, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
@use '~@mezzanine-ui/system/palette'; | ||
@use '~@mezzanine-ui/system/transition'; | ||
@use '../button/utils' as btn-utils; | ||
@use './anchor' as *; | ||
|
||
$bar-width: 1px !default; | ||
$anchor-left-padding: 12px !default; | ||
|
||
.#{$prefix} { | ||
width: 100%; | ||
display: grid; | ||
grid-template-columns: 1fr; | ||
gap: 8px; | ||
position: relative; | ||
|
||
&__bar { | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
z-index: 0; | ||
width: $bar-width; | ||
height: 100%; | ||
background-color: palette.color(border); | ||
} | ||
|
||
&__anchor { | ||
@include btn-utils.reset(); | ||
|
||
display: inline-grid; | ||
position: relative; | ||
z-index: 1; | ||
width: 100%; | ||
border-left: $bar-width solid palette.color(border); | ||
padding-left: $anchor-left-padding; | ||
text-align: left; | ||
color: palette.color(action-inactive); | ||
transition: transition.standard(border-left), transition.standard(color); | ||
|
||
&:hover { | ||
color: palette.color(primary); | ||
} | ||
|
||
&--active { | ||
color: palette.color(primary); | ||
border-left: $bar-width solid palette.color(primary); | ||
} | ||
} | ||
} |
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 @@ | ||
$prefix: mzn-anchor; |
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 @@ | ||
@forward './anchor'; |
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,8 @@ | ||
export const anchorPrefix = 'mzn-anchor'; | ||
|
||
export const anchorClasses = { | ||
host: anchorPrefix, | ||
bar: `${anchorPrefix}__bar`, | ||
anchor: `${anchorPrefix}__anchor`, | ||
anchorActive: `${anchorPrefix}__anchor--active`, | ||
} as const; |
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 @@ | ||
export * from './anchor'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Meta, ArgTypes, Description } from '@storybook/blocks'; | ||
import Anchor from '.'; | ||
import * as AnchorStories from './Anchor.stories'; | ||
|
||
<Meta of={AnchorStories} /> | ||
|
||
# Anchor | ||
|
||
<Description of={Anchor} /> | ||
|
||
[Source Code](https://github.com/Mezzanine-UI/mezzanine/blob/main/packages/react/src/Anchor/Anchor.tsx) | ||
|
||
<ArgTypes of={Anchor} /> |
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,29 @@ | ||
import { cleanup, fireEvent, render } from '../../__test-utils__'; | ||
import { | ||
describeForwardRefToHTMLElement, | ||
describeHostElementClassNameAppendable, | ||
} from '../../__test-utils__/common'; | ||
import Anchor from '.'; | ||
|
||
const mockList = [ | ||
{ | ||
id: 'foo', | ||
name: 'foo', | ||
}, | ||
{ | ||
id: 'bar', | ||
name: 'bar', | ||
}, | ||
]; | ||
|
||
describe('<Anchor />', () => { | ||
afterEach(cleanup); | ||
|
||
describeForwardRefToHTMLElement(HTMLDivElement, (ref) => | ||
render(<Anchor ref={ref} list={mockList} />), | ||
); | ||
|
||
describeHostElementClassNameAppendable('foo', (className) => | ||
render(<Anchor className={className} list={mockList} />), | ||
); | ||
}); |
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,67 @@ | ||
import { Meta } from '@storybook/react'; | ||
import Anchor from './Anchor'; | ||
import { useState } from 'react'; | ||
import Typography from '../Typography'; | ||
|
||
export default { | ||
title: 'Others/Anchor', | ||
} as Meta; | ||
|
||
const anchorList = [ | ||
{ | ||
id: 'Anchor1', | ||
name: 'Anchor1', | ||
}, | ||
{ | ||
id: 'Anchor2', | ||
name: 'Anchor2', | ||
}, | ||
{ | ||
id: 'lorem ipsum lorem ipsum lorem ipsum', | ||
name: 'lorem ipsum lorem ipsum lorem ipsum', | ||
}, | ||
{ | ||
id: 'Anchor4', | ||
name: 'Anchor4', | ||
}, | ||
{ | ||
id: 'Anchor5', | ||
name: 'Anchor5', | ||
}, | ||
]; | ||
|
||
export const Basics = () => { | ||
const [currentActiveId, setCurrentActiveId] = useState<string>( | ||
anchorList[0].id, | ||
); | ||
|
||
return ( | ||
<div | ||
style={{ | ||
display: 'grid', | ||
gridAutoFlow: 'row', | ||
gap: '12px', | ||
}} | ||
> | ||
<Typography variant="h4" color="secondary"> | ||
Non Ellipsis | ||
</Typography> | ||
<Anchor | ||
activeAnchorId={currentActiveId} | ||
list={anchorList} | ||
maxWidth={180} | ||
onClick={(nextAnchorId) => setCurrentActiveId(nextAnchorId)} | ||
/> | ||
<Typography variant="h4" color="secondary"> | ||
Ellipsis | ||
</Typography> | ||
<Anchor | ||
activeAnchorId={currentActiveId} | ||
ellipsis | ||
list={anchorList} | ||
maxWidth={200} | ||
onClick={(nextAnchorId) => setCurrentActiveId(nextAnchorId)} | ||
/> | ||
</div> | ||
); | ||
}; |
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,83 @@ | ||
import { forwardRef } from 'react'; | ||
import { anchorClasses as classes } from '@mezzanine-ui/core/anchor'; | ||
import { cx } from '../utils/cx'; | ||
import { NativeElementPropsWithoutKeyAndRef } from '../utils/jsx-types'; | ||
import Typography from '../Typography'; | ||
|
||
export interface AnchorProps | ||
extends Omit<NativeElementPropsWithoutKeyAndRef<'div'>, 'onClick'> { | ||
/** The current active anchor ID */ | ||
activeAnchorId?: string; | ||
/** Whether apply ellipsis or not | ||
* @default false | ||
*/ | ||
ellipsis?: boolean; | ||
/** | ||
* Anchor list. | ||
*/ | ||
list: { | ||
id: string; | ||
name: string; | ||
}[]; | ||
/** | ||
* The maximum width for anchor container. This might be useful when you need to set `ellipsis: true`. | ||
*/ | ||
maxWidth?: number; | ||
/** | ||
* Trigger when user click on any anchor. | ||
*/ | ||
onClick?: (nextAnchorId: string) => void; | ||
} | ||
|
||
/** | ||
* The react component for `mezzanine` anchor. | ||
* This component should always be full width of its parent. | ||
*/ | ||
const Anchor = forwardRef<HTMLDivElement, AnchorProps>( | ||
function Anchor(props, ref) { | ||
const { | ||
activeAnchorId, | ||
className, | ||
children, | ||
ellipsis = false, | ||
list, | ||
maxWidth, | ||
onClick, | ||
style, | ||
...rest | ||
} = props; | ||
|
||
const resolvedStyle = { | ||
...(style || {}), | ||
...(maxWidth ? { maxWidth: `${maxWidth}px` } : {}), | ||
}; | ||
|
||
return ( | ||
<div | ||
ref={ref} | ||
className={cx(classes.host, className)} | ||
style={resolvedStyle} | ||
{...rest} | ||
> | ||
<div className={classes.bar} /> | ||
{list.map((anchor) => ( | ||
<button | ||
key={anchor.id} | ||
type="button" | ||
onClick={() => onClick?.(anchor.id)} | ||
className={cx( | ||
classes.anchor, | ||
activeAnchorId === anchor.id && classes.anchorActive, | ||
)} | ||
> | ||
<Typography variant="input3" color="inherit" ellipsis={ellipsis}> | ||
{anchor.name} | ||
</Typography> | ||
</button> | ||
))} | ||
</div> | ||
); | ||
}, | ||
); | ||
|
||
export default Anchor; |
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 @@ | ||
export { AnchorProps, default } from './Anchor'; |
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
2 changes: 1 addition & 1 deletion
2
packages/react/src/DateRangePicker/DateRangePickerCalendar.spec.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
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
Oops, something went wrong.