@geoinsight/react-components 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/cjs/index.js +3 -2
  2. package/dist/esm/index.js +3 -2
  3. package/geoinsight-react-components-0.2.1.tgz +0 -0
  4. package/package.json +1 -1
  5. package/.babelrc.json +0 -16
  6. package/.storybook/main.js +0 -11
  7. package/.storybook/preview.js +0 -43
  8. package/rollup.config.js +0 -40
  9. package/src/components/accordion/index.css +0 -40
  10. package/src/components/accordion/index.stories.tsx +0 -55
  11. package/src/components/accordion/index.tsx +0 -78
  12. package/src/components/accordion/index.types.ts +0 -44
  13. package/src/components/button/index.css +0 -80
  14. package/src/components/button/index.stories.tsx +0 -46
  15. package/src/components/button/index.tsx +0 -58
  16. package/src/components/button/index.types.ts +0 -43
  17. package/src/components/input/index.css +0 -31
  18. package/src/components/input/index.stories.tsx +0 -34
  19. package/src/components/input/index.tsx +0 -25
  20. package/src/components/input/index.types.ts +0 -29
  21. package/src/components/loading/index.css +0 -8
  22. package/src/components/loading/index.stories.tsx +0 -20
  23. package/src/components/loading/index.tsx +0 -14
  24. package/src/components/loading/index.types.ts +0 -12
  25. package/src/components/text-area/index.css +0 -54
  26. package/src/components/text-area/index.stories.tsx +0 -30
  27. package/src/components/text-area/index.tsx +0 -62
  28. package/src/components/text-area/index.types.ts +0 -37
  29. package/src/context/loading/index.stories.tsx +0 -37
  30. package/src/context/loading/index.tsx +0 -111
  31. package/src/context/themeContext.tsx +0 -93
  32. package/src/decorators/withColorScheme.tsx +0 -29
  33. package/src/decorators/withLoading.tsx +0 -31
  34. package/src/decorators/withWrapper.tsx +0 -9
  35. package/src/index.ts +0 -7
  36. package/src/stories/Introduction.stories.mdx +0 -211
  37. package/src/stories/assets/code-brackets.svg +0 -1
  38. package/src/stories/assets/colors.svg +0 -1
  39. package/src/stories/assets/comments.svg +0 -1
  40. package/src/stories/assets/direction.svg +0 -1
  41. package/src/stories/assets/flow.svg +0 -1
  42. package/src/stories/assets/loading.gif +0 -0
  43. package/src/stories/assets/plugin.svg +0 -1
  44. package/src/stories/assets/repo.svg +0 -1
  45. package/src/stories/assets/spinner_2.png +0 -0
  46. package/src/stories/assets/stackalt.svg +0 -1
  47. package/src/styles/variables.css +0 -115
  48. package/src/types/palette-theme.d.ts +0 -5
  49. package/src/utils/themes.ts +0 -1
  50. package/tsconfig.json +0 -21
@@ -1,25 +0,0 @@
1
- import { Input as InputProps } from "./index.types";
2
- import "./index.css";
3
-
4
- export function Input({
5
- className = "",
6
- classNameGroup = "",
7
- errorMessage = "" ,
8
- inputRef,
9
- styleGroup,
10
- ...rest
11
- }: InputProps) {
12
- return (
13
- <div className={`input-group ${classNameGroup}`}
14
- style={styleGroup}>
15
- <input
16
- ref={inputRef}
17
- className={`input ${errorMessage ? "input--error" : ""} ${className}`}
18
- {...rest}
19
- />
20
- {errorMessage && <span className="error">{errorMessage}</span>}
21
- </div>
22
- );
23
- }
24
-
25
- export default Input;
@@ -1,29 +0,0 @@
1
- import { dataTheme } from "data-theme";
2
- import { CSSProperties, Ref } from "react";
3
-
4
- export interface Input extends React.InputHTMLAttributes<HTMLInputElement> {
5
- /**
6
- * Custom css class name.
7
- */
8
- className?: string;
9
- /**
10
- * Custom css class name for group wrapper.
11
- */
12
- classNameGroup?: string;
13
- /**
14
- * Data theme for the html. `${themes}`
15
- */
16
- paletteTheme?: dataTheme;
17
- /**
18
- * Error message to show when input has an error.
19
- */
20
- errorMessage?: string;
21
- /**
22
- * Ref react elemnt to use
23
- */
24
- inputRef?: Ref<HTMLInputElement>;
25
- /**
26
- * Style input group wrapper
27
- */
28
- styleGroup?: CSSProperties;
29
- }
@@ -1,8 +0,0 @@
1
- .loading {
2
- align-items: center;
3
- display: flex;
4
- flex-direction: column;
5
- height: 100%;
6
- justify-content: center;;
7
- position: relative;
8
- }
@@ -1,20 +0,0 @@
1
- import { Meta, StoryObj } from "@storybook/react";
2
-
3
- import { Loading } from "./index";
4
- import { withColorScheme } from "../../decorators/withColorScheme";
5
-
6
- const meta: Meta<typeof Loading> = {
7
- title: "Example/Loading",
8
- component: Loading,
9
- decorators: [withColorScheme]
10
- };
11
-
12
- export default meta;
13
-
14
- type Story = StoryObj<typeof Loading>;
15
-
16
- export const Primary: Story = {
17
- args: {
18
- img: ""
19
- },
20
- };
@@ -1,14 +0,0 @@
1
- import { Loading as LoadingProps } from "./index.types";
2
- import "./index.css";
3
- import loading from "../../stories/assets/loading.gif";
4
-
5
- export function Loading({ img, children }: LoadingProps) {
6
- return (
7
- <div className="loading">
8
- <img src={img ? img : loading} />
9
- {children}
10
- </div>
11
- );
12
- }
13
-
14
- export default Loading;
@@ -1,12 +0,0 @@
1
- import React, { CSSProperties, Ref } from "react";
2
-
3
- export interface Loading {
4
- /**
5
- * Image or gif used
6
- */
7
- img?: string;
8
- /**
9
- * Message that its sent
10
- */
11
- children?: React.ReactNode;
12
- }
@@ -1,54 +0,0 @@
1
- .textarea {
2
- margin-bottom: var(--spacing-8);
3
- position: relative;
4
- }
5
-
6
- .textarea__input {
7
- background-color: var(--color-white);
8
- box-sizing: border-box;
9
- border-radius: var(--spacing-8);
10
- border: 2px solid var(--color-primary);
11
- cursor: text;
12
- color: var(--color-black);
13
- outline: none;
14
- padding: var(--spacing-8) var(--spacing-16);
15
- resize: vertical;
16
- width: 100%;
17
- }
18
-
19
- .textarea__input:hover {
20
- border: 3px solid var(--color-primary-700);
21
- }
22
-
23
- .textarea__button {
24
- background: var(--color-primary);
25
- border: 2px solid var(--color-secondary);
26
- box-shadow: 2px 4px 2px 1px rgba(0, 0, 0, 0.25);
27
- border-radius: 0px 0px var(--spacing-8) var(--spacing-8);
28
- bottom: 0;
29
- cursor: pointer;
30
- left: 0;
31
- padding-bottom: -20px;
32
- position: absolute;
33
- width: 100%;
34
- }
35
-
36
- .textarea__button > svg {
37
- color: var(--color-neutral-100);
38
- }
39
-
40
- .textarea__button:disabled {
41
- cursor: unset;
42
- opacity: 0.5;
43
- pointer-events: none;
44
- }
45
-
46
- .textarea__button:hover {
47
- background: var(--color-secondary);
48
- color: var(--color-neutral-100);
49
- }
50
-
51
- .textarea__button--show {
52
- background: var(--color-primary-700);
53
- color: var(--color-neutral-100);
54
- }
@@ -1,30 +0,0 @@
1
- import { Meta, StoryObj } from "@storybook/react";
2
-
3
- import { TextArea } from "./index";
4
- import { withColorScheme } from "../../decorators/withColorScheme";
5
-
6
- const meta: Meta<typeof TextArea> = {
7
- title: "Example/TextArea",
8
- component: TextArea,
9
- argTypes: {
10
- backgroundColor: { control: "color" },
11
- },
12
- decorators: [withColorScheme]
13
- };
14
-
15
- export default meta;
16
-
17
- type Story = StoryObj<typeof TextArea>;
18
-
19
- export const Active: Story = {
20
- args: {
21
- placeholder: "Insert a value",
22
- disabled: false
23
- },
24
- };
25
-
26
- export const Disabled: Story = {
27
- args: {
28
- placeholder: "Insert a value",
29
- },
30
- };
@@ -1,62 +0,0 @@
1
- import React, { MutableRefObject, useRef, useState } from "react";
2
- import clsx from "clsx";
3
- import { TbArrowsDiagonal2 } from "react-icons/tb";
4
- import { TextArea as TextAreaProps } from "./index.types";
5
- import "./index.css";
6
-
7
- export function TextArea({
8
- className = "",
9
- disabled = true,
10
- hasToggleButton = true,
11
- hideHeight = "5rem",
12
- placeholder = "",
13
- showHeight = "10rem",
14
- style = {},
15
- textareaClassName = "",
16
- ...rest
17
- }: TextAreaProps): JSX.Element {
18
- const ref = useRef() as MutableRefObject<HTMLTextAreaElement>;
19
- const [isShow, setIsShow] = useState<boolean>(false);
20
-
21
- const handleClickToggle = () => {
22
- if (ref && ref.current) {
23
- if (isShow) {
24
- ref.current.style.height = hideHeight;
25
- } else {
26
- ref.current.style.height = showHeight; //(48 + ref.current.scrollHeight) + 'px';
27
- }
28
- setIsShow((prev) => !prev);
29
- }
30
- };
31
-
32
- return (
33
- <div className={clsx("textarea", className)} style={style}>
34
- <textarea
35
- ref={ref}
36
- className={clsx("textarea__input", textareaClassName)}
37
- style={
38
- {
39
- height: hasToggleButton ? hideHeight : showHeight,
40
- } as React.CSSProperties
41
- }
42
- placeholder={placeholder}
43
- disabled={disabled}
44
- {...rest}
45
- />
46
- {hasToggleButton && (
47
- <button
48
- className={clsx(
49
- "textarea__button",
50
- isShow && "textarea__button--show"
51
- )}
52
- onClick={handleClickToggle}
53
- disabled={disabled}
54
- >
55
- <TbArrowsDiagonal2 size="1.5rem" />
56
- </button>
57
- )}
58
- </div>
59
- );
60
- }
61
-
62
- export default TextArea;
@@ -1,37 +0,0 @@
1
- import { dataTheme } from "data-theme";
2
- import { CSSProperties, Ref } from "react";
3
-
4
- export interface TextArea extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
5
- /**
6
- * Custom css class name textarea wrapper.
7
- */
8
- className?: string;
9
- /**
10
- * Disable prop
11
- */
12
- disabled?: boolean;
13
- /**
14
- * Check if there is a toggle button
15
- */
16
- hasToggleButton?: boolean;
17
- /**
18
- * Minimum height if toggle button is true
19
- */
20
- hideHeight?: string;
21
- /**
22
- * Placeholder for textarea html tag
23
- */
24
- placeholder?: string;
25
- /**
26
- * Maximum height if toggle button is false
27
- */
28
- showHeight?: string;
29
- /**
30
- * Style textarea group wrapper
31
- */
32
- style?: CSSProperties;
33
- /**
34
- * Classname of the textarea
35
- */
36
- textareaClassName?: string;
37
- }
@@ -1,37 +0,0 @@
1
- import { Meta, StoryObj } from "@storybook/react";
2
-
3
- import { LoadingProvider } from ".";
4
- import { withColorScheme } from "../../decorators/withColorScheme";
5
- import { withLoading } from "../../decorators/withLoading";
6
- import spinner from "../../stories/assets/spinner_2.png";
7
-
8
- const meta: Meta<typeof LoadingProvider> = {
9
- title: "Context/Loading",
10
- component: () => <div></div>,
11
- decorators: [withColorScheme, withLoading],
12
- };
13
-
14
- export default meta;
15
-
16
- type Story = StoryObj<typeof LoadingProvider>;
17
-
18
- export const Basic: Story = {};
19
-
20
- export const CustomMessage: Story = {
21
- parameters: {
22
- loadingOptions: {
23
- message: "Updating form",
24
- },
25
- },
26
- };
27
-
28
- export const CustomImage: Story = {
29
- parameters: {
30
- loadingOptions: {
31
- isRef: true,
32
- },
33
- },
34
- args: {
35
- img: spinner,
36
- },
37
- };
@@ -1,111 +0,0 @@
1
- import React, {
2
- ReactNode,
3
- RefObject,
4
- createContext,
5
- useContext,
6
- useEffect,
7
- useReducer,
8
- } from "react";
9
- import Loading from "../../components/loading";
10
-
11
- type Action = {
12
- type: "set_ref" | "start_loading" | "stop_loading" | "set_message";
13
- ref?: RefObject<ReactNode>;
14
- message?: string;
15
- };
16
- type State = {
17
- isLoading: boolean;
18
- message?: string | React.ReactNode;
19
- ref?: RefObject<ReactNode>;
20
- };
21
- type Context = {
22
- state: State;
23
- setRef: (ref: RefObject<ReactNode>) => void;
24
- setMessage: (message: string) => void;
25
- startLoading: () => void;
26
- stopLoading: () => void;
27
- };
28
- type LoadingProviderProps = { children: React.ReactNode };
29
- type UseLoadingProps = {
30
- ref?: RefObject<ReactNode>;
31
- message?: string;
32
- };
33
-
34
- const LoadingContext = createContext<Context | undefined>(undefined);
35
-
36
- function loadingReducer(state: State, action: Action) {
37
- switch (action.type) {
38
- case "set_ref": {
39
- return { ...state, ref: action.ref };
40
- }
41
- case "start_loading": {
42
- return { ...state, isLoading: true };
43
- }
44
- case "stop_loading": {
45
- return { ...state, isLoading: false };
46
- }
47
- case "set_message": {
48
- return { ...state, message: action.message };
49
- }
50
- default: {
51
- throw new Error(`Unhandled action type: ${action.type}`);
52
- }
53
- }
54
- }
55
-
56
- function LoadingProvider({ children }: LoadingProviderProps) {
57
- const [{ isLoading, message, ref }, dispatch] = useReducer(loadingReducer, {
58
- isLoading: false,
59
- message: "Loading",
60
- ref: undefined,
61
- });
62
-
63
- const setRef = (ref: RefObject<ReactNode>) => {
64
- dispatch({ type: "set_ref", ref });
65
- };
66
-
67
- const setMessage = (message: string) => {
68
- dispatch({ type: "set_message", message });
69
- };
70
-
71
- const startLoading = () => {
72
- dispatch({ type: "start_loading" });
73
- };
74
-
75
- const stopLoading = () => {
76
- dispatch({ type: "stop_loading" });
77
- };
78
-
79
- return (
80
- <LoadingContext.Provider
81
- value={{
82
- state: { ref, message, isLoading },
83
- setMessage,
84
- setRef,
85
- startLoading,
86
- stopLoading,
87
- }}
88
- >
89
- {!ref && <Loading>{message}</Loading>}
90
- {children}
91
- </LoadingContext.Provider>
92
- );
93
- }
94
-
95
- function useLoading({ ref, message }: UseLoadingProps = {}) {
96
- const context = useContext(LoadingContext);
97
-
98
- // only happens if there is an initial mode value.
99
- useEffect(() => {
100
- ref && context?.setRef(ref);
101
- message && context?.setMessage(message);
102
- }, []);
103
-
104
- if (context === undefined) {
105
- throw new Error("useLoading must be used within a LoadingProvider");
106
- }
107
-
108
- return context;
109
- }
110
-
111
- export { LoadingContext, LoadingProvider, useLoading };
@@ -1,93 +0,0 @@
1
- import { PaletteTheme } from "palette-theme";
2
- import React, {
3
- Dispatch,
4
- SetStateAction,
5
- createContext,
6
- useContext,
7
- useEffect,
8
- useState,
9
- } from "react";
10
-
11
- type DataTheme = "light" | "dark";
12
-
13
- type State = {
14
- dataTheme?: DataTheme;
15
- switchDataTheme: (mode: DataTheme) => void;
16
- paletteTheme?: PaletteTheme;
17
- switchPaletteTheme: (mode: PaletteTheme) => void;
18
- };
19
- type ThemeProviderProps = { children: React.ReactNode };
20
- type UseThemeProps = {
21
- dataTheme?: DataTheme;
22
- paletteTheme?: PaletteTheme;
23
- };
24
-
25
- const ThemeContext = createContext<State | undefined>(undefined);
26
-
27
- function ThemeProvider({ children }: ThemeProviderProps) {
28
- const [dataTheme, setDataTheme] = useState<DataTheme>();
29
- const [paletteTheme, setPaletteTheme] = useState<PaletteTheme>();
30
-
31
- useEffect(() => {
32
- if (window.matchMedia) {
33
- if (localStorage.getItem("data-theme")) {
34
- document.documentElement.setAttribute(
35
- "data-theme",
36
- localStorage.getItem("data-theme") as string
37
- );
38
- setDataTheme(localStorage.getItem("data-theme") as DataTheme);
39
- } else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
40
- document.documentElement.setAttribute("data-theme", "dark");
41
- setDataTheme("dark");
42
- }
43
- }
44
- }, []);
45
-
46
- const switchDataTheme = (mode: DataTheme) => {
47
- document.documentElement.setAttribute("data-theme", mode);
48
- setDataTheme(mode);
49
- localStorage.setItem("data-theme", mode);
50
- };
51
-
52
- const switchPaletteTheme = (mode: PaletteTheme) => {
53
- document.documentElement.setAttribute("palette-theme", mode);
54
- setPaletteTheme(mode);
55
- localStorage.setItem("palette-theme", mode);
56
- };
57
-
58
- return (
59
- <ThemeContext.Provider
60
- value={{ dataTheme, switchDataTheme, paletteTheme, switchPaletteTheme }}
61
- >
62
- {children}
63
- </ThemeContext.Provider>
64
- );
65
- }
66
-
67
- function useTheme({
68
- dataTheme = undefined,
69
- paletteTheme = "water",
70
- }: UseThemeProps = {}) {
71
- const context = useContext(ThemeContext);
72
-
73
- // only happens if there is an initial mode value.
74
- useEffect(() => {
75
- if (dataTheme && !localStorage.getItem("data-theme")) {
76
- context?.switchDataTheme(dataTheme);
77
- } else if (!dataTheme && localStorage.getItem("data-theme")) {
78
- localStorage.removeItem("data-theme");
79
- }
80
- }, []);
81
-
82
- useEffect(() => {
83
- context?.switchPaletteTheme(paletteTheme);
84
- }, []);
85
-
86
- if (context === undefined) {
87
- throw new Error("useTheme must be used within a ThemeProvider");
88
- }
89
-
90
- return context;
91
- }
92
-
93
- export { ThemeContext, ThemeProvider, useTheme };
@@ -1,29 +0,0 @@
1
- import { StoryContext, StoryFn } from "@storybook/react";
2
- import { ThemeProvider, useTheme } from "../context/themeContext";
3
- import "../styles/variables.css";
4
- import { useEffect } from "react";
5
-
6
- export const withColorScheme = (Story: StoryFn, context: StoryContext) => {
7
- return (
8
- <ThemeProvider>
9
- <Wrapped Story={Story} context={context} />
10
- </ThemeProvider>
11
- );
12
- };
13
-
14
- export const Wrapped = ({ Story, context } : { Story: StoryFn, context: StoryContext}) => {
15
- const { theme, palette } = context.globals;
16
- const switchTheme = useTheme();
17
-
18
- useEffect (()=> {
19
- switchTheme.switchDataTheme(theme)
20
- }, [theme]);
21
-
22
- useEffect (()=> {
23
- switchTheme.switchPaletteTheme(palette)
24
- }, [palette]);
25
-
26
- return (
27
- <Story />
28
- );
29
- };
@@ -1,31 +0,0 @@
1
- import { useRef } from "react";
2
- import { StoryContext, StoryFn } from "@storybook/react";
3
- import { LoadingProvider, useLoading } from "../context/loading";
4
-
5
- const LoadingProviderMock = ({ Story, loadingOptions, loadingArgs }) => {
6
- const ref = useRef();
7
- const loading = useLoading({
8
- ...(loadingOptions?.isRef && { ref: ref }),
9
- ...(loadingOptions?.message && { message: loadingOptions.message }),
10
- });
11
-
12
- // initialize stuff here
13
- return (
14
- <>
15
- {loading.state.ref && <img ref={ref} src={loadingArgs.img} />}
16
- <Story />
17
- </>
18
- );
19
- };
20
-
21
- export const withLoading = (Story: StoryFn, context: StoryContext) => {
22
- return (
23
- <LoadingProvider>
24
- <LoadingProviderMock
25
- Story={Story}
26
- loadingOptions={context.parameters.loadingOptions}
27
- loadingArgs={context.args}
28
- />
29
- </LoadingProvider>
30
- );
31
- };
@@ -1,9 +0,0 @@
1
- import { StoryContext, StoryFn } from "@storybook/react";
2
-
3
- export const withWrapper = (Story: StoryFn, context: StoryContext) => {
4
- return (
5
- <div style={{height: "300px"}}>
6
- <Story />
7
- </div>
8
- );
9
- };
package/src/index.ts DELETED
@@ -1,7 +0,0 @@
1
- import "../src/styles/variables.css";
2
-
3
- export { Button } from "./components/button";
4
- export { Input } from "./components/input";
5
- export { TextArea } from "./components/text-area";
6
-
7
- export { ThemeContext, ThemeProvider, useTheme } from "./context/themeContext";