-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding first approach of component DropdownItem
- Loading branch information
1 parent
f8742bd
commit 5402113
Showing
6 changed files
with
124 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"testing": { | ||
"basicTestId": "test-dropdown-item", | ||
"testText": "Lorem Ipsum" | ||
}, | ||
"storybook": { | ||
"parameters": { | ||
"componentSubtitle": "Dropdown's item single unit, which can be a link, a divider or text", | ||
"docs": { | ||
"description": { | ||
"component": "Can be used as an anchor link `<a>`, you can also use a `<div>` and insert almost any type of content." | ||
} | ||
} | ||
} | ||
} | ||
} |
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,23 @@ | ||
import React from 'react' | ||
import { StoryFn, Meta } from '@storybook/react' | ||
// COMPONENTS | ||
import DropdownItem from '.' | ||
// TYPES & INTERFACES | ||
// MOCKS | ||
import { storybook, testing } from './index.mocks.json' | ||
|
||
export default { | ||
title: 'Atoms/DropdownItem', | ||
component: DropdownItem, | ||
...storybook, | ||
args: { | ||
itemText: testing.testText | ||
} | ||
} as Meta<typeof DropdownItem> | ||
|
||
const Template: StoryFn<typeof DropdownItem> = args => ( | ||
<DropdownItem {...args} /> | ||
) | ||
|
||
export const BasicExample = Template.bind({}) | ||
BasicExample.storyName = 'Basic Example' |
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,18 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import '@testing-library/jest-dom' | ||
// COMPONENTS | ||
import DropdownItem from '.' | ||
// TYPES & INTERFACES | ||
// MOCKS | ||
import { testing } from './index.mocks.json' | ||
|
||
describe('DropdownItem', () => { | ||
const { basicTestId, testText } = testing | ||
|
||
test('Should render the component', () => { | ||
render(<DropdownItem itemText={testText} />) | ||
const testDropdownItem = screen.getByTestId(basicTestId) | ||
expect(testDropdownItem).toBeInTheDocument() | ||
}) | ||
}) |
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,47 @@ | ||
import React from 'react' | ||
// COMPONENTS | ||
// TYPES & INTERFACES | ||
import { DropdownItemProps } from '../../../interfaces/atomProps' | ||
// PARSERS | ||
import { parseClasses, parseTestId } from '../../../functions/parsers' | ||
|
||
const DropdownItem: React.FC<DropdownItemProps> = ({ | ||
testId = null, | ||
cssClasses = null, | ||
style = null, | ||
itemText, | ||
isLink = false, | ||
isDivider = false, | ||
isActiveItem = false, | ||
onClick = null | ||
}) => { | ||
const itemTypeClass = isDivider ? 'dropdown-divider' : 'dropdown-item' | ||
const dropdownItemClasses = parseClasses([ | ||
itemTypeClass, | ||
isActiveItem && !isDivider ? 'is-active' : null, | ||
cssClasses | ||
]) | ||
|
||
const dropdownItemConfig = { | ||
'data-testid': | ||
testId ?? | ||
parseTestId({ tag: itemTypeClass, parsedClasses: dropdownItemClasses }), | ||
'className': dropdownItemClasses, | ||
'style': style ?? undefined, | ||
'onClick': onClick ?? undefined | ||
} | ||
|
||
if (isLink) { | ||
return <a {...dropdownItemConfig}>{itemText}</a> | ||
} | ||
|
||
if (isDivider) return <hr {...dropdownItemConfig} /> | ||
|
||
return ( | ||
<div {...dropdownItemConfig}> | ||
<p>{itemText}</p> | ||
</div> | ||
) | ||
} | ||
|
||
export default DropdownItem |
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