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

Ability to augment style of certain elements #2

Open
tgallacher opened this issue May 30, 2022 · 0 comments
Open

Ability to augment style of certain elements #2

tgallacher opened this issue May 30, 2022 · 0 comments

Comments

@tgallacher
Copy link

Summary

Hey! 👋

Lovely lib 💪

As some of the prop getters include some minimal style settings for the relevant carousel element(s), it would be amazing if this could be extended.

For example, in some situations I would like to expand this style to customise certain aspects of the layout/design, etc. In order to avoid adding extra HTML markup to offer styling points -- which can actually break some layouts -- it would be great if the prop getters supported a style object as part of the input arg.

For example (using the README example):

export const MyCarousel = () => {
  const items = new Array(10).fill(null).map((_, idx) => ({
    id: idx,
    name: `item number ${idx}`,
  }));

  const {
    getSectionProps,
    getHeadingProps,
    getCarouselWrapperProps,
    getCarouselProps,
    getCarouselItemProps,
    getButtonProps,
    getAnnouncerProps,
    state,
  } = usePony({ numItems: items.length });

  // some example CSS
  const itemStyle = {
    margin: '1rem 0',
    border: '1px solid blue',
  };
  const ulStyle = {
    margin: 0,
    padding: 0
  }

  return (
    <div {...getSectionProps()}>
      <h1 {...getHeadingProps()}>Heading</h1>
      <div {...getCarouselWrapperProps()}>
        <ul {...getCarouselProps(ulStyle)}>
          {items.map((item, idx) => (
            <li key={idx} {...getCarouselItemProps(idx, itemStyle)}>
              {item.name}
            </li>
          ))}
        </ul>
      </div>
      <button {...getButtonProps(ActionKind.Previous)}>Previous</button>
      <button {...getButtonProps(ActionKind.Next)}>Next</button>
      <div {...getAnnouncerProps()}>
        <p>{`Item ${state.activeSlideIndex + 1} of ${items.length}`}</p>
      </div>
    </div>
  );
};

and so on.

The following prop getters should support this style arg, as they return a minimal style prop:

  • getCarouselWrapperProps
  • getCarouselProps
  • getCarouselItemProps
  • getAnnouncerProps
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

No branches or pull requests

1 participant