-
Notifications
You must be signed in to change notification settings - Fork 89
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 #2509 from anuradha9712/feat-chat-date-separator-c…
…omponent feat(dateSeparator): add chat date separator component
- Loading branch information
Showing
9 changed files
with
179 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,23 @@ | ||
import * as React from 'react'; | ||
import DateSeparator from './dateSeparator'; | ||
import { BaseProps } from '@/utils/types'; | ||
|
||
export interface ChatProps extends BaseProps { | ||
/** | ||
* React Node to be rendered inside `Chat` | ||
*/ | ||
children: React.ReactNode; | ||
} | ||
|
||
export const Chat = (props: ChatProps) => { | ||
const { children, ...rest } = props; | ||
return ( | ||
<div data-test="DesignSystem-Chat" {...rest}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
Chat.DateSeparator = DateSeparator; | ||
|
||
export default Chat; |
29 changes: 29 additions & 0 deletions
29
core/components/molecules/chat/dateSeparator/DateSeparator.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as React from 'react'; | ||
import { Text } from '@/index'; | ||
import { BaseProps } from '@/utils/types'; | ||
import classNames from 'classnames'; | ||
|
||
export interface DateSeparatorProps extends BaseProps { | ||
/** | ||
* Specifies the date to be displayed | ||
*/ | ||
date: React.ReactText; | ||
} | ||
|
||
const DateSeparator: React.FC<DateSeparatorProps> = (props) => { | ||
const { date, className, ...rest } = props; | ||
return ( | ||
<Text | ||
appearance="subtle" | ||
className={classNames('pt-7 pb-6 d-flex justify-content-center', className)} | ||
role="separator" | ||
aria-label={String(date)} | ||
data-test="DesignSystem-Chat-DateSeparator" | ||
{...rest} | ||
> | ||
{date} | ||
</Text> | ||
); | ||
}; | ||
|
||
export default DateSeparator; |
36 changes: 36 additions & 0 deletions
36
core/components/molecules/chat/dateSeparator/__stories__/all.story.jsx
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,36 @@ | ||
import * as React from 'react'; | ||
import { Chat } from '@/index'; | ||
|
||
export const dateSeparator = () => { | ||
return ( | ||
<Chat> | ||
<Chat.DateSeparator date="May 21, 2024" /> | ||
</Chat> | ||
); | ||
}; | ||
|
||
const customCode = `() => { | ||
return ( | ||
<Chat> | ||
<Chat.DateSeparator date="May 21, 2024" /> | ||
</Chat> | ||
) | ||
}`; | ||
|
||
export default { | ||
title: 'Components/Chat/Separator/Date Separator', | ||
component: Chat, | ||
subcomponents: { | ||
'Chat.DateSeparator': Chat.DateSeparator, | ||
'Chat.NewMessage': Chat.NewMessage, | ||
'Chat.UnreadMessage': Chat.UnreadMessage, | ||
}, | ||
parameters: { | ||
docs: { | ||
docPage: { | ||
title: 'Chat', | ||
customCode, | ||
}, | ||
}, | ||
}, | ||
}; |
63 changes: 63 additions & 0 deletions
63
core/components/molecules/chat/dateSeparator/__tests__/DateSeparator.test.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { testHelper, filterUndefined, valueHelper, testMessageHelper } from '@/utils/testHelper'; | ||
import { Chat } from '@/index'; | ||
import { ChatProps as Props } from '@/index.type'; | ||
|
||
const date = '01 Jan 2025'; | ||
|
||
const mapper = { | ||
date: valueHelper(date, { required: true, iterate: false }), | ||
}; | ||
|
||
describe('Chat Date Separator component snapshot', () => { | ||
const testFunc = (props: Record<string, any>): void => { | ||
const attr = filterUndefined(props) as Props; | ||
|
||
it(testMessageHelper(attr), () => { | ||
const { baseElement } = render( | ||
<Chat> | ||
<Chat.DateSeparator date={date} {...attr} /> | ||
</Chat> | ||
); | ||
expect(baseElement).toMatchSnapshot(); | ||
}); | ||
}; | ||
|
||
testHelper(mapper, testFunc); | ||
}); | ||
|
||
describe('Chat Date Separator component', () => { | ||
it('renders children', () => { | ||
const { getByTestId } = render( | ||
<Chat> | ||
<Chat.DateSeparator date={date} /> | ||
</Chat> | ||
); | ||
expect(getByTestId('DesignSystem-Chat-DateSeparator')).toBeInTheDocument(); | ||
expect(getByTestId('DesignSystem-Chat-DateSeparator').textContent).toMatch(date); | ||
}); | ||
|
||
describe('Chat Date Separator Component with overwrite class', () => { | ||
it('overwrite Chat Date Separator class', () => { | ||
const { getByTestId } = render( | ||
<Chat> | ||
<Chat.DateSeparator date={date} className="custom-class" /> | ||
</Chat> | ||
); | ||
expect(getByTestId('DesignSystem-Chat-DateSeparator')).toHaveClass('custom-class'); | ||
}); | ||
}); | ||
|
||
it('Chat Date Separator Component with overwrite data-test attribute', () => { | ||
const testDataValue = 'DesignSystem-DateSeparator-TestValue'; | ||
const { getByTestId } = render( | ||
<Chat> | ||
<Chat.DateSeparator date={date} data-test={testDataValue} /> | ||
</Chat> | ||
); | ||
|
||
const dateElement = getByTestId(testDataValue); | ||
expect(dateElement.getAttribute('data-test')).toBe(testDataValue); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
...mponents/molecules/chat/dateSeparator/__tests__/__snapshots__/DateSeparator.test.tsx.snap
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,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Chat Date Separator component snapshot | ||
date: "01 Jan 2025" | ||
1`] = ` | ||
<body> | ||
<div> | ||
<div | ||
data-test="DesignSystem-Chat" | ||
> | ||
<span | ||
aria-label="01 Jan 2025" | ||
class="Text Text--subtle Text--regular pt-7 pb-6 d-flex justify-content-center" | ||
data-test="DesignSystem-Chat-DateSeparator" | ||
role="separator" | ||
> | ||
01 Jan 2025 | ||
</span> | ||
</div> | ||
</div> | ||
</body> | ||
`; |
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,2 @@ | ||
export { default } from './DateSeparator'; | ||
export * from './DateSeparator'; |
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,2 @@ | ||
export { default } from './Chat'; | ||
export * from './Chat'; |
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