Skip to content
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

feat(atomic): add button function for lit components #4857

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

y-lakhdar
Copy link
Contributor

@y-lakhdar y-lakhdar commented Jan 15, 2025

Add Lit equivalent to <Button> functional element.

Also replaced button.tsx to stencil-button.tsx which is responsible for all the file changes

Usage

With Stencil

return (
  <Button
    style="primary"
    text={i18n.t('load-more-results')}
    part="load-more-results-button"
    class="my-2 p-3 font-bold"
    onClick={() => onClick()}
  ></Button>
);

With Lit

return button({
  props: {
    style: 'primary',
    text: i18n.t('load-more-results'),
    part: 'load-more-results-button',
    class: 'my-2 p-3 font-bold',
    onClick: () => onClick(),
  },
});

Question

Lit does not natively support spreading attributes as we do in .tsx files, which can lead to code repetition. To address this, we could use lit-helpers to avoid duplicating attributes, properties, and events while maintaining consistency in our patterns.

WDYT

Copy link

Pull Request Report

PR Title

✅ Title follows the conventional commit spec.

Live demo links

Bundle Size

File Old (kb) New (kb) Change (%)
case-assist 243.8 243.8 0
commerce 355 355 0
search 414.9 414.9 0
insight 406.2 406.2 0
recommendation 256.1 256.1 0
ssr 408.4 408.4 0
ssr-commerce 372.4 372.4 0

SSR Progress

Use case SSR (#) CSR (#) Progress (%)
search 39 44 89
recommendation 0 4 0
case-assist 0 6 0
insight 0 27 0
commerce 0 15 0
Detailed logs search : buildInteractiveResult
search : buildInteractiveInstantResult
search : buildInteractiveRecentResult
search : buildInteractiveCitation
search : buildGeneratedAnswer
recommendation : missing SSR support
case-assist : missing SSR support
insight : missing SSR support
commerce : missing SSR support

Comment on lines +4 to +27
interface LoadMoreButtonProps {
i18n: i18n;
onClick: () => void;
moreAvailable: boolean;
label?: 'load-more-results' | 'load-more-products';
}

export function loadMoreButton({
i18n,
onClick,
moreAvailable,
label,
}: LoadMoreButtonProps) {
if (!moreAvailable) {
return;
}
const props: 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')});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename this to 'button.ts' and rename the stencil one to 'stencil-button' like the normal button ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants