Skip to content

Commit

Permalink
feat: add docs to stories
Browse files Browse the repository at this point in the history
  • Loading branch information
bearkfear committed Aug 7, 2024
1 parent 0be6a7f commit 49f817d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const preview: Preview = {
defaultValue: true, // Enable dark mode by default on all stories
},
},
//👇 Enables auto-generated documentation for all stories
tags: ["autodocs"],
};

export default preview;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@continha/ui",
"version": "1.0.8",
"version": "1.1.0",
"private": false,
"repository": {
"url": "https://github.com/bearkfear/ui"
Expand Down
25 changes: 25 additions & 0 deletions src/components/ui/form/selector/hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import get from "lodash.get";
import { useCallback } from "react";

export function useSelectorHelpers<O, VP extends keyof O, LP extends keyof O>(
labelPath: LP,
valuePath: VP,
) {
const getValue = useCallback(
(option: O) => {
return get(option, valuePath);
},
[valuePath],
);
const getLabel = useCallback(
(option: O) => {
return get(option, labelPath);
},
[labelPath],
);

return {
getLabel,
getValue,
};
}
17 changes: 6 additions & 11 deletions src/components/ui/form/selector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Button } from "../../button";
import * as Popover from "../../popover";
import { SelectorContent } from "./content";
import type { SelectorCommonProps, TOption } from "./model";
import { useSelectorHelpers } from "./hooks";

export interface SelectorProps<
O extends TOption,
Expand All @@ -27,19 +28,13 @@ export function Selector<O extends TOption, VP extends FieldPath<O>>(
ref: React.ForwardedRef<HTMLButtonElement>,
) {
const [width, setWidth] = useState(1);
const getValue = useCallback(
(option: O) => {
return get(option, props.valuePath);
},
[props.valuePath],
);
const getLabel = useCallback(
(option: O) => {
return get(option, props.labelPath);
},
[props.labelPath],
const { getLabel, getValue } = useSelectorHelpers<O>(

Check failure on line 31 in src/components/ui/form/selector/index.tsx

View workflow job for this annotation

GitHub Actions / build (20)

Expected 3 type arguments, but got 1.
props.labelPath,
props.valuePath,
);

const item = (option: O) => get(option, props.labelPath);

const selectedOption = useMemo(() => {
return props.options.find((option) => isEqual(getValue(option), value));
}, [props.options, value, getValue]);
Expand Down

0 comments on commit 49f817d

Please sign in to comment.