-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:coveo/ui-kit into KIT-3948
- Loading branch information
Showing
13 changed files
with
148 additions
and
59 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
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
70 changes: 70 additions & 0 deletions
70
packages/atomic/src/components/common/load-more/button.spec.ts
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,70 @@ | ||
import enTranslations from '@/dist/atomic/lang/en.json'; | ||
import i18next, {i18n as I18n} from 'i18next'; | ||
import {html, render} from 'lit'; | ||
import {loadMoreButton} from './button'; | ||
|
||
describe('loadMoreButton', () => { | ||
let container: HTMLElement; | ||
let i18n: I18n; | ||
|
||
beforeAll(async () => { | ||
i18n = i18next.createInstance(); | ||
await i18n.init({ | ||
lng: 'en', | ||
resources: { | ||
en: { | ||
translation: enTranslations, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
}); | ||
|
||
afterEach(() => { | ||
document.body.removeChild(container); | ||
}); | ||
|
||
const renderLoadMoreButton = (props: { | ||
moreAvailable: boolean; | ||
label?: 'load-more-results' | 'load-more-products'; | ||
}) => { | ||
render( | ||
html`${loadMoreButton({ | ||
props: { | ||
i18n, | ||
onClick: () => {}, | ||
moreAvailable: props.moreAvailable, | ||
label: props.label ?? 'load-more-results', | ||
}, | ||
})}`, | ||
container | ||
); | ||
}; | ||
|
||
test('should render nothing when moreAvailable is false', () => { | ||
renderLoadMoreButton({moreAvailable: false}); | ||
|
||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
|
||
test('should render a button with the correct props', () => { | ||
renderLoadMoreButton({moreAvailable: true}); | ||
|
||
const button = container.querySelector('button'); | ||
expect(button).toHaveClass('btn-primary'); | ||
expect(button).toHaveClass('my-2'); | ||
expect(button).toHaveClass('p-3'); | ||
expect(button).toHaveClass('font-bold'); | ||
}); | ||
|
||
test('should render the children as the label', () => { | ||
renderLoadMoreButton({moreAvailable: true, label: 'load-more-products'}); | ||
|
||
const button = container.querySelector('button'); | ||
expect(button).toHaveTextContent('Load more products'); | ||
}); | ||
}); |
23 changes: 13 additions & 10 deletions
23
packages/atomic/src/components/common/load-more/button.ts
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 |
---|---|---|
@@ -1,27 +1,30 @@ | ||
import {FunctionalComponent} from '@/src/utils/functional-component-utils'; | ||
import {i18n} from 'i18next'; | ||
import {html} from 'lit'; | ||
import {button, ButtonProps} from '../button'; | ||
|
||
interface LoadMoreButtonProps { | ||
i18n: i18n; | ||
onClick: () => void; | ||
moreAvailable: boolean; | ||
label?: 'load-more-results' | 'load-more-products'; | ||
label: 'load-more-results' | 'load-more-products'; | ||
} | ||
|
||
export function loadMoreButton({ | ||
i18n, | ||
onClick, | ||
moreAvailable, | ||
label, | ||
}: LoadMoreButtonProps) { | ||
export const loadMoreButton: FunctionalComponent<LoadMoreButtonProps> = ({ | ||
props, | ||
}) => { | ||
const {i18n, onClick, moreAvailable, label} = props; | ||
if (!moreAvailable) { | ||
return; | ||
} | ||
const props: ButtonProps = { | ||
const buttonProps: ButtonProps = { | ||
style: 'primary', | ||
part: 'load-more-results-button', | ||
class: 'my-2 p-3 font-bold', | ||
onClick: () => onClick(), | ||
}; | ||
return button({props, children: i18n.t(label || 'load-more-results')}); | ||
} | ||
return button({ | ||
props: buttonProps, | ||
children: html`${i18n.t(label)}`, | ||
}); | ||
}; |
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,18 @@ | ||
import {TemplateResult} from 'lit'; | ||
|
||
export interface FunctionalComponent<T> { | ||
({props}: {props: T}): TemplateResult | undefined; | ||
} | ||
|
||
export interface FunctionalComponentWithChildren<T> { | ||
({ | ||
props, | ||
children, | ||
}: { | ||
props: T; | ||
children: | ||
| TemplateResult | ||
| TemplateResult[] | ||
| (TemplateResult | undefined)[]; | ||
}): TemplateResult; | ||
} |
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