Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
feat(bullets-wrapper): export internal arrow component
Browse files Browse the repository at this point in the history
This allows to import the styled bullets wrapper-component and overwrite styled-component styles.
  • Loading branch information
Tobi-mmt committed Oct 1, 2021
1 parent f1f8813 commit ad9697e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
15 changes: 13 additions & 2 deletions src/bullets.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { Meta, Story as IStory } from "@storybook/react/types-6-0";
import Bullet, { BulletComponentType } from "../src/components/bullet";
import Bullets from "../src/components/bullets";
import styled from "styled-components";

import Slider, { SliderProps } from ".";
Expand Down Expand Up @@ -75,12 +76,22 @@ CustomBullets.args = {
BulletComponent,
};

export const ModufiedCustomBullets = Story.bind({});
export const ModufiedCustomBullet = Story.bind({});
const ModifiedBulletComponent = styled(Bullet)`
background-color: green;
`;
ModufiedCustomBullet.storyName = "modified 'bullet' component";
ModufiedCustomBullet.args = {
hasBullets: true,
BulletComponent: ModifiedBulletComponent,
};

export const ModufiedCustomBullets = Story.bind({});
const ModifiedBulletsComponent = styled(Bullets)`
background-color: green;
`;
ModufiedCustomBullets.storyName = "modified 'bullets' component";
ModufiedCustomBullets.args = {
hasBullets: true,
BulletComponent: ModifiedBulletComponent,
BulletsComponent: ModifiedBulletsComponent,
};
17 changes: 17 additions & 0 deletions src/components/bullets/bullets.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react";
import styled from "styled-components";

export interface BulletsProps {
children: React.ReactElement;
}

export type BulletsComponentType = (props: BulletsProps) => React.ReactElement;

const Bullets = styled.div`
position: absolute;
bottom: 0;
width: 100%;
z-index: 1;
`;

export default Bullets;
3 changes: 3 additions & 0 deletions src/components/bullets/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Bullets, { BulletsComponentType, BulletsProps } from "./bullets";
export default Bullets;
export { BulletsComponentType, BulletsProps };
24 changes: 7 additions & 17 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@ import styled from "styled-components";
import { useSprings, animated } from "react-spring";
import { useGesture } from "react-use-gesture";

import Arrow, {
ArrowComponentType,
ArrowStyle,
} from "./components/arrow/arrow";
import Bullet, {
BulletComponentType,
BulletStyle,
} from "./components/bullet/bullet";
import Arrow, { ArrowComponentType, ArrowStyle } from "./components/arrow";
import Bullet, { BulletComponentType, BulletStyle } from "./components/bullet";
import Bullets, { BulletsComponentType } from "./components/bullets";

const StyledSliderArrows = styled.div`
top: 50%;
Expand All @@ -29,13 +24,6 @@ const StyledBulletList = styled.ul`
margin: 15px 0;
`;

const StyledBullets = styled.div`
position: absolute;
bottom: 0;
width: 100%;
z-index: 1;
`;

const StyledWrapper = styled.div`
width: 100%;
height: 100%;
Expand All @@ -61,6 +49,7 @@ export interface SliderProps {
arrowStyle?: ArrowStyle;
auto?: number;
BulletComponent?: BulletComponentType;
BulletsComponent?: BulletsComponentType;
bulletStyle?: BulletStyle;
children?: React.ReactNode[];
hasArrows?: boolean;
Expand All @@ -80,6 +69,7 @@ const Slider: React.FunctionComponent<SliderProps> = ({
arrowStyle = {},
auto = 0,
BulletComponent = Bullet,
BulletsComponent = Bullets,
bulletStyle = {},
children = [],
hasArrows = false,
Expand Down Expand Up @@ -268,9 +258,9 @@ const Slider: React.FunctionComponent<SliderProps> = ({
</StyledSliderArrows>
)}
{hasBullets && (
<StyledBullets>
<BulletsComponent>
<StyledBulletList>{bullets()}</StyledBulletList>
</StyledBullets>
</BulletsComponent>
)}
{springProps.map(({ offset }, index) => (
<animated.div
Expand Down

0 comments on commit ad9697e

Please sign in to comment.