-
Notifications
You must be signed in to change notification settings - Fork 4
feat:#243 add features component #265
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
41b5b88
feat:#243 add features component
ss-dimasm 0f8b9fe
chore: update html node
ss-dimasm 4ea8af8
chore: update interface
ss-dimasm fe1b19f
Merge branch 'main' into feat/#243-add-feature-component
ss-dimasm ee9c59c
chore: export feature
ss-dimasm 61de84b
Merge branch 'main' into feat/#243-add-feature-component
ss-dimasm ba9fc27
feat: add tooltip integration
ss-dimasm 442605e
Merge branch 'main' into feat/#243-add-feature-component
ss-dimasm 7ecc13a
Merge branch 'main' into feat/#243-add-feature-component
ss-dimasm b581184
chore: add comment in storybook
ss-dimasm 101f336
chore: eslint
ss-dimasm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/components/features/__tests__/__snapshots__/features.test.tsx.snap
This file contains hidden or 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,40 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Features > should render the component 1`] = ` | ||
<DocumentFragment> | ||
<ul | ||
class="mocked-styled-2 el-features" | ||
> | ||
<li | ||
aria-describedby="tooltip-id-test-static-id" | ||
aria-label="Bathrooms" | ||
class="mocked-styled-1 el-features-item" | ||
data-visible-id="tooltip-id-test-static-id" | ||
> | ||
<span | ||
class="mocked-styled-0 el-features-item-icon" | ||
> | ||
<span> | ||
icon | ||
</span> | ||
</span> | ||
1 | ||
</li> | ||
<li | ||
aria-describedby="tooltip-id-test-static-id" | ||
aria-label="Bedrooms" | ||
class="mocked-styled-1 el-features-item" | ||
data-visible-id="tooltip-id-test-static-id" | ||
> | ||
<span | ||
class="mocked-styled-0 el-features-item-icon" | ||
> | ||
<span> | ||
icon | ||
</span> | ||
</span> | ||
2 | ||
</li> | ||
</ul> | ||
</DocumentFragment> | ||
`; |
This file contains hidden or 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,19 @@ | ||
import { render } from '@testing-library/react' | ||
import { Features } from '../features' | ||
|
||
describe('Features', () => { | ||
it('should render the component', () => { | ||
expect( | ||
render( | ||
<Features> | ||
<Features.Item icon={<span>icon</span>} aria-label="Bathrooms"> | ||
1 | ||
</Features.Item> | ||
<Features.Item icon={<span>icon</span>} aria-label="Bedrooms"> | ||
2 | ||
</Features.Item> | ||
</Features>, | ||
).asFragment(), | ||
).toMatchSnapshot() | ||
}) | ||
}) |
This file contains hidden or 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,22 @@ | ||
import { FC, HTMLAttributes, ReactNode } from 'react' | ||
import { ElFeaturesItem, ElFeaturesItemIcon } from './styles' | ||
import { useTooltip } from '../tooltip/use-tooltip' | ||
import { Tooltip } from '../tooltip' | ||
|
||
export interface FeaturesItemProps extends HTMLAttributes<HTMLLIElement> { | ||
icon: ReactNode | ||
children: ReactNode | ||
'aria-label': string | ||
} | ||
|
||
export const FeaturesItem: FC<FeaturesItemProps> = ({ icon, children, 'aria-label': ariaLabel, ...props }) => { | ||
const { getTooltipProps, getTriggerProps } = useTooltip() | ||
|
||
return ( | ||
<ElFeaturesItem aria-label={ariaLabel} {...props} {...getTriggerProps()}> | ||
<ElFeaturesItemIcon>{icon}</ElFeaturesItemIcon> | ||
{children} | ||
<Tooltip {...getTooltipProps()} description={ariaLabel} position="top" /> | ||
</ElFeaturesItem> | ||
) | ||
} |
This file contains hidden or 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,27 @@ | ||
import { Meta, Canvas, Controls } from '@storybook/blocks' | ||
import { RenderHtmlMarkup } from '../../storybook/render-html-markup' | ||
import * as FeaturesStories from './features.stories' | ||
|
||
<Meta of={FeaturesStories} /> | ||
|
||
# Features | ||
|
||
The features component allows users to provide quick details about a property. | ||
|
||
The features component has at least one feature item. Each feature item has a representative icon and an alphanumeric value. | ||
|
||
<Controls /> | ||
|
||
## Default | ||
|
||
<Canvas of={FeaturesStories.Default} /> | ||
|
||
<RenderHtmlMarkup of={FeaturesStories.Default} /> | ||
|
||
## Tooltip support | ||
|
||
Use a tooltip on hover to provide more context for the icon's meaning | ||
|
||
<Canvas of={FeaturesStories.DisplayTooltip} /> | ||
|
||
<RenderHtmlMarkup of={FeaturesStories.DisplayTooltip} /> |
This file contains hidden or 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 type { Meta, StoryObj } from '@storybook/react' | ||
|
||
import { Features } from './features' | ||
import { Icon } from '../icon' | ||
import { ElTooltip } from '../tooltip' | ||
import { ElFeaturesItem, ElFeaturesItemIcon } from './styles' | ||
|
||
const meta = { | ||
title: 'Components/Features', | ||
component: Features, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
argTypes: { | ||
children: { | ||
control: false, | ||
}, | ||
}, | ||
args: { | ||
children: null, | ||
}, | ||
} satisfies Meta<typeof Features> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof meta> | ||
|
||
export const Default: Story = { | ||
render: ({}) => ( | ||
<Features> | ||
<Features.Item aria-label="Bedrooms" icon={<Icon icon="bed" />}> | ||
1 | ||
</Features.Item> | ||
<Features.Item aria-label="Bathooms" icon={<Icon icon="bath" />}> | ||
2 | ||
</Features.Item> | ||
<Features.Item aria-label="Cars" icon={<Icon icon="car" />}> | ||
5 | ||
</Features.Item> | ||
<Features.Item aria-label="Areas" icon={<Icon icon="appLauncher" />}> | ||
850 sqm | ||
</Features.Item> | ||
</Features> | ||
), | ||
} | ||
|
||
export const DisplayTooltip = { | ||
render: ({}) => { | ||
return ( | ||
<Features> | ||
<ElFeaturesItem aria-label="Bathrooms"> | ||
<ElTooltip | ||
role="tooltip" | ||
data-position="top" | ||
style={{ transform: 'translate(-40%, -120%)', maxWidth: '400px' }} | ||
aria-live="assertive" | ||
> | ||
Bathrooms | ||
</ElTooltip> | ||
<ElFeaturesItemIcon> | ||
<Icon icon="bed" /> | ||
</ElFeaturesItemIcon> | ||
1 | ||
</ElFeaturesItem> | ||
</Features> | ||
) | ||
}, | ||
} |
This file contains hidden or 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,19 @@ | ||
import { FC, HTMLAttributes, ReactNode } from 'react' | ||
import { FeaturesItem } from './features.atoms' | ||
import { ElFeatures } from './styles' | ||
|
||
export interface FeaturesProps extends HTMLAttributes<HTMLUListElement> { | ||
children: ReactNode | ||
} | ||
|
||
type FeaturesFC = FC<FeaturesProps> & { | ||
Item: typeof FeaturesItem | ||
} | ||
|
||
const Features: FeaturesFC = (props) => { | ||
return <ElFeatures {...props} /> | ||
} | ||
|
||
Features.Item = FeaturesItem | ||
|
||
export { Features } |
This file contains hidden or 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,3 @@ | ||
export * from './features.atoms' | ||
export * from './features' | ||
export * from './styles' |
This file contains hidden or 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,35 @@ | ||
import { styled } from '@linaria/react' | ||
import { ElIcon } from '../icon' | ||
|
||
export const ElFeaturesItemIcon = styled.span` | ||
color: var(--icon-primary); | ||
width: var(--icon-sm); | ||
height: var(--icon-sm); | ||
font-size: var(--size-4); | ||
` | ||
|
||
export const ElFeaturesItem = styled.li` | ||
display: inline-flex; | ||
align-items: flex-start; | ||
gap: var(--spacing-1); | ||
|
||
color: var(--text-primary); | ||
font-family: var(--font-family); | ||
font-size: var(--font-size-2xs); | ||
font-style: normal; | ||
font-weight: var(--font-weight-regular); | ||
line-height: var(--line-height-2xs); | ||
letter-spacing: var(--letter-spacing-2xs); | ||
|
||
${ElIcon} { | ||
color: inherit; | ||
font-size: inherit; | ||
} | ||
` | ||
|
||
export const ElFeatures = styled.ul` | ||
display: inline-flex; | ||
align-items: flex-start; | ||
gap: var(--spacing-3); | ||
flex-wrap: wrap; | ||
` |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.