Skip to content

Commit

Permalink
Merge pull request #8 from liuxian496/developer
Browse files Browse the repository at this point in the history
Developer
  • Loading branch information
liuxian496 committed May 22, 2024
2 parents d850565 + d6c4711 commit b56e7df
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 50 deletions.
49 changes: 27 additions & 22 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,32 @@ const coverageConfig: AddonOptionsBabel = {
};

const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-onboarding",
"@storybook/addon-links",
"@storybook/addon-essentials",
"@chromatic-com/storybook",
"@storybook/addon-interactions",
{
name: "@storybook/addon-coverage",
options: {
...coverageConfig,
},
},
"@storybook/addon-mdx-gfm"
],
framework: {
name: "@storybook/react-vite",
options: {},
},
docs: {
autodocs: "tag",
},
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],

addons: [
"@storybook/addon-onboarding",
"@storybook/addon-links",
"@storybook/addon-essentials",
"@chromatic-com/storybook",
"@storybook/addon-interactions",
{
name: "@storybook/addon-coverage",
options: {
...coverageConfig,
},
},
"@storybook/addon-mdx-gfm",
],

framework: {
name: "@storybook/react-vite",
options: {},
},

docs: {},

typescript: {
reactDocgen: "react-docgen-typescript"
}
};
export default config;
3 changes: 3 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { Preview } from "@storybook/react";

import "litten/dist/assets/button.css";


const preview: Preview = {
parameters: {
controls: {
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# [1.1.0](https://github.com/liuxian496/cyndi/compare/v1.0.0...v1.1.0) (2024-05-22)


### Features

* 添加updateScrollTop ([f2218ff](https://github.com/liuxian496/cyndi/commit/f2218fff86b2f29c2e190693e9f1a9291c1b85c3))



# [1.0.0](https://github.com/liuxian496/cyndi/compare/v0.2.2...v1.0.0) (2024-05-11)


Expand Down
37 changes: 19 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cyndi",
"private": false,
"version": "1.0.0",
"version": "1.1.0",
"type": "module",
"module": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -27,30 +27,30 @@
"prepare": "husky"
},
"dependencies": {
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"lodash": "^4.17.21"
"react-dom": "^18.2.0"
},
"peerDependencies": {
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"lodash": "^4.17.21"
"react-dom": "^18.2.0"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.3.3",
"@chromatic-com/storybook": "^1.4.0",
"@commitlint/cli": "^19.2.2",
"@commitlint/config-conventional": "^19.2.2",
"@storybook/addon-coverage": "^1.0.1",
"@storybook/addon-essentials": "^8.0.9",
"@storybook/addon-interactions": "^8.0.9",
"@storybook/addon-links": "^8.0.9",
"@storybook/addon-mdx-gfm": "^8.0.9",
"@storybook/addon-onboarding": "^8.0.9",
"@storybook/blocks": "^8.0.9",
"@storybook/react": "^8.0.9",
"@storybook/react-vite": "^8.0.9",
"@storybook/test": "^8.0.9",
"@storybook/test-runner": "^0.17.0",
"@storybook/addon-coverage": "^1.0.3",
"@storybook/addon-essentials": "^8.1.1",
"@storybook/addon-interactions": "^8.1.1",
"@storybook/addon-links": "^8.1.1",
"@storybook/addon-mdx-gfm": "^8.1.1",
"@storybook/addon-onboarding": "^8.1.1",
"@storybook/blocks": "^8.1.1",
"@storybook/react": "^8.1.1",
"@storybook/react-vite": "^8.1.1",
"@storybook/test": "^8.1.1",
"@storybook/test-runner": "^0.18.1",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@typescript-eslint/eslint-plugin": "^7.2.0",
Expand All @@ -63,11 +63,12 @@
"eslint-plugin-react-refresh": "^0.4.6",
"eslint-plugin-storybook": "^0.8.0",
"husky": "^9.0.11",
"less": "^4.2.0",
"litten": "^0.9.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rollup-plugin-visualizer": "^5.12.0",
"storybook": "^8.0.9",
"storybook": "^8.1.1",
"typescript": "^5.2.2",
"vite": "^5.2.0",
"vite-plugin-dts": "^3.8.3"
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export { getPrefixNs } from "./util/getPrefixNs";
export { isEmptyString } from "./util/isEmptyString";

export { printArrayItem } from "./util/printArrayItem";

export { updateScrollTop } from "./util/updateScroll";
15 changes: 15 additions & 0 deletions src/stories/util.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,19 @@ export declare function printArrayItem(list?: object[]): string;
`
} language="tsx" />
</Summary>

## printArrayItem
<Summary>
<Source code={
`
/**
* 移动纵向滚动条,将指定的元素显示在可视区域
* @param element 待移动的元素
* @param scrollContainer 包含滚动条的容器
*/
export declare function updateScrollTop(element: HTMLElement, scrollContainer: HTMLElement): void;
`
} language="tsx" />
</Summary>
14 changes: 10 additions & 4 deletions src/stories/util.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { Meta, StoryObj } from "@storybook/react";
import { GetPrefixNsTest } from "../test/util/getPrefixNsTest";
import { IsEmptyStringTest } from "../test/util/isEmptyStringTest";
import { PrintArrayItemTest } from "../test/util/printArrayItemTest";
import { UpdateScrollTopTest } from "../test/util/updateScrollTopTest";

export default {
title: "Example/Util"
title: "Example/Util",
} as Meta;

export type UtilStory = StoryObj;
Expand All @@ -15,12 +16,17 @@ export const GetPrefixNs = {
...GetPrefixNsTest,
};

export const IsEmptyString = {
name: "isEmptyString",
...IsEmptyStringTest,
};

export const PrintArrayItem = {
name: "printArrayItem",
...PrintArrayItemTest,
};

export const IsEmptyString = {
name: "isEmptyString",
...IsEmptyStringTest,
export const UpdateScrollTop = {
name: "updateScrollTest",
...UpdateScrollTopTest,
};
2 changes: 2 additions & 0 deletions src/test/util/getPrefixNsTest.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from "react";

import { within, expect } from "@storybook/test";
import { UtilStory } from "../../stories/util.stories";

Expand Down
2 changes: 2 additions & 0 deletions src/test/util/isEmptyStringTest.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from "react";

import { within, expect } from "@storybook/test";
import { UtilStory } from "../../stories/util.stories";

Expand Down
14 changes: 14 additions & 0 deletions src/test/util/item.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.container {
height: 240px;
overflow-y: auto;
overflow-x: hidden;
width: 200px;
border: 1px solid salmon;
}

.item {
height: 36px;
line-height: 36px;
padding-left: 10px;
border-bottom: 1px solid #ababab;
}
3 changes: 1 addition & 2 deletions src/test/util/printArrayItemTest.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import "litten/dist/assets/button.css";
import { useState } from "react";
import React, { useState } from "react";

import { userEvent, within, expect } from "@storybook/test";
import { UtilStory } from "../../stories/util.stories";
Expand Down
151 changes: 151 additions & 0 deletions src/test/util/updateScrollTopTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import React, { forwardRef, useRef } from "react";
import "./item.less";

import { Button } from "litten/dist/button";
import { within, expect, userEvent } from "@storybook/test";

import { UtilStory } from "../../stories/util.stories";

import { updateScrollTop } from "../../util/updateScroll";

interface ItemProps {
name: string;
}

const Item = forwardRef<HTMLDivElement, ItemProps>(function Item(
props: ItemProps,
ref
) {
const { name } = props;
return (
<div ref={ref} className="item">
{name}
</div>
);
});

const Test = () => {
const containerRef = useRef<HTMLDivElement>(null);
const item1Ref = useRef<HTMLDivElement>(null);
const item3Ref = useRef<HTMLDivElement>(null);
const item10Ref = useRef<HTMLDivElement>(null);
const item12Ref = useRef<HTMLDivElement>(null);
const item16Ref = useRef<HTMLDivElement>(null);

function handleShow1Click() {
updateScrollTop(
item1Ref.current as HTMLElement,
containerRef.current as HTMLElement
);
}

function handleShow3Click() {
updateScrollTop(
item3Ref.current as HTMLElement,
containerRef.current as HTMLElement
);
}

function handleShow12Click() {
updateScrollTop(
item12Ref.current as HTMLElement,
containerRef.current as HTMLElement
);
}

function handleShow10Click() {
updateScrollTop(
item10Ref.current as HTMLElement,
containerRef.current as HTMLElement
);
}

function handleShow16Click() {
updateScrollTop(
item16Ref.current as HTMLElement,
containerRef.current as HTMLElement
);
}

return (
<>
<div data-testid="container" ref={containerRef} className="container">
<Item ref={item1Ref} name="001" />
<Item name="002" />
<Item ref={item3Ref} name="003" />
<Item name="004" />

<Item name="005" />
<Item name="006" />
<Item name="007" />
<Item name="008" />

<Item name="009" />
<Item ref={item10Ref} name="010" />
<Item name="011" />
<Item ref={item12Ref} name="012" />

<Item name="013" />
<Item name="014" />
<Item name="015" />
<Item ref={item16Ref} name="016" />
</div>
<Button onClick={handleShow10Click}>show 10</Button>
<Button onClick={handleShow3Click}>show 3</Button>
<Button onClick={handleShow12Click}>show 12</Button>
<Button onClick={handleShow16Click}>show 16</Button>
<Button onClick={handleShow1Click}>show 1</Button>
</>
);
};

export const UpdateScrollTopTest: UtilStory = {
render: () => <Test />,
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement);

const container =canvas.getByTestId("container");

// const item001 = canvas.getByText("001");
// const item003 = canvas.getByText("003");
// const item010 = canvas.getByText("010");
// const item012 = canvas.getByText("012");
// const item016 = canvas.getByText("016");

const btu001 = canvas.getByText("show 1");
const btu003 = canvas.getByText("show 3");
const btu010 = canvas.getByText("show 10");
const btu012 = canvas.getByText("show 12");
const btu016 = canvas.getByText("show 16");

await step('Click "show 10" button. Then container scrollTop to be equal 147.', async () => {
await userEvent.click(btu010);

await expect(container.scrollTop).toEqual(147);
});

await step('Click "show 3" button. Then container scrollTop to be equal 74.', async () => {
await userEvent.click(btu003);

await expect(container.scrollTop).toEqual(74);
});

await step('Click "show 12" button. Then container scrollTop to be equal 221.', async () => {
await userEvent.click(btu012);

await expect(container.scrollTop).toEqual(221);
});

await step('Click "show 16" button. Then container scrollTop to be equal 352.', async () => {
await userEvent.click(btu016);

await expect(container.scrollTop).toEqual(352);
});

await step('Click "show 11" button. Then container scrollTop to be equal 0.', async () => {
await userEvent.click(btu001);

await expect(container.scrollTop).toEqual(0);
});
},
};
1 change: 1 addition & 0 deletions src/updateScroll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { updateScrollTop } from "./util/updateScroll";
Loading

0 comments on commit b56e7df

Please sign in to comment.