@rpg-engine/long-bow 0.1.32 → 0.1.35

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.
@@ -1,23 +1,31 @@
1
1
  import React from 'react';
2
+ import styled from 'styled-components';
2
3
 
3
- export enum IButtonTypes {
4
+ export enum ButtonTypes {
4
5
  RPGUIButton = 'rpgui-button',
5
6
  RPGUIGoldButton = 'rpgui-button golden',
6
7
  }
7
8
 
8
- export interface IButtonsProps {
9
+ export interface IButtonProps {
9
10
  children: React.ReactNode;
10
- type: IButtonTypes;
11
+ buttonType: ButtonTypes;
11
12
  }
12
13
 
13
- export const Button: React.FC<IButtonsProps> = ({
14
- children,
15
- type,
16
- ...props
17
- }) => {
14
+ export const Button: React.FC<
15
+ IButtonProps &
16
+ React.DetailedHTMLProps<
17
+ React.ButtonHTMLAttributes<HTMLButtonElement>,
18
+ HTMLButtonElement
19
+ >
20
+ > = ({ children, buttonType, ...props }) => {
18
21
  return (
19
- <button className={type} type="button" {...props}>
22
+ <ButtonContainer className={`${buttonType}`} {...props}>
20
23
  <p>{children}</p>
21
- </button>
24
+ </ButtonContainer>
22
25
  );
23
26
  };
27
+
28
+ const ButtonContainer = styled.button<any>`
29
+ height: 45px;
30
+ font-size: 11.5px;
31
+ `;
@@ -0,0 +1,64 @@
1
+ import React, { useEffect, useState } from 'react';
2
+
3
+ export interface ICheckItems {
4
+ label: string;
5
+ value: string;
6
+ }
7
+
8
+ export interface ICheckProps {
9
+ items: ICheckItems[];
10
+ onChange: (selectedValues: IChecklistSelectedValues) => void;
11
+ }
12
+
13
+ interface IChecklistSelectedValues {
14
+ [label: string]: boolean;
15
+ }
16
+
17
+ export const CheckButton: React.FC<ICheckProps> = ({ items, onChange }) => {
18
+ const generateSelectedValuesList = () => {
19
+ const selectedValues: IChecklistSelectedValues = {};
20
+
21
+ items.forEach((item) => {
22
+ selectedValues[item.label] = false;
23
+ });
24
+
25
+ return selectedValues;
26
+ };
27
+
28
+ const [selectedValues, setSelectedValues] =
29
+ useState<IChecklistSelectedValues>(generateSelectedValuesList());
30
+
31
+ const handleClick = (label: string) => {
32
+ setSelectedValues({
33
+ ...selectedValues,
34
+ [label]: !selectedValues[label],
35
+ });
36
+ };
37
+
38
+ useEffect(() => {
39
+ if (selectedValues) {
40
+ onChange(selectedValues);
41
+ }
42
+ }, [selectedValues]);
43
+
44
+ return (
45
+ <div id="elemento-checkbox">
46
+ {items?.map((element, index) => {
47
+ return (
48
+ <div key={`${element.label}_${index}`}>
49
+ <input
50
+ className="rpgui-checkbox"
51
+ type="checkbox"
52
+ checked={selectedValues[element.label]}
53
+ onChange={() => {}}
54
+ />
55
+ <label onClick={() => handleClick(element.label)}>
56
+ {element.label}
57
+ </label>
58
+ <br />
59
+ </div>
60
+ );
61
+ })}
62
+ </div>
63
+ );
64
+ };
@@ -0,0 +1,57 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { v4 as uuidv4 } from 'uuid';
3
+ import { _RPGUI } from './RPGUIRoot';
4
+
5
+ export interface IOptionsProps {
6
+ id: number;
7
+ value: string;
8
+ option: string;
9
+ }
10
+
11
+ export interface IDropdownProps {
12
+ options: IOptionsProps[];
13
+ width?: string;
14
+ onChange: (value: string) => void;
15
+ }
16
+
17
+ export const Dropdown: React.FC<IDropdownProps> = ({
18
+ options,
19
+ width,
20
+ onChange,
21
+ }) => {
22
+ const dropdownId = uuidv4();
23
+
24
+ const [selectedValue, setSelectedValue] = useState<string>('');
25
+
26
+ useEffect(() => {
27
+ const element = document.getElementById(`rpgui-dropdown-${dropdownId}`);
28
+ const dropdownValue = _RPGUI.get_value(element);
29
+ setSelectedValue(dropdownValue);
30
+
31
+ element?.addEventListener('change', (event: any) => {
32
+ setSelectedValue(event?.target.value);
33
+ });
34
+ }, []);
35
+
36
+ useEffect(() => {
37
+ if (selectedValue) {
38
+ onChange(selectedValue);
39
+ }
40
+ }, [selectedValue]);
41
+
42
+ return (
43
+ <select
44
+ id={`rpgui-dropdown-${dropdownId}`}
45
+ style={{ width: width }}
46
+ className="rpgui-dropdown"
47
+ >
48
+ {options.map((option) => {
49
+ return (
50
+ <option key={option.id} value={option.value}>
51
+ {option.option}
52
+ </option>
53
+ );
54
+ })}
55
+ </select>
56
+ );
57
+ };
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+
3
+ export interface IInputProps
4
+ extends React.DetailedHTMLProps<
5
+ React.InputHTMLAttributes<HTMLInputElement>,
6
+ HTMLInputElement
7
+ > {}
8
+
9
+ export const Input: React.FC<IInputProps> = ({ ...props }) => {
10
+ return <input {...props} />;
11
+ };
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import { RPGUIRoot } from './RPGUIRoot';
4
+
5
+ export interface IBarProps {
6
+ max: number;
7
+ value: number;
8
+ color: 'red' | 'blue' | 'green';
9
+ }
10
+
11
+ export const ProgressBar: React.FC<IBarProps> = ({ max, value, color }) => {
12
+ const calculatePercentageValue = function (max: number, value: number) {
13
+ if (value > max) {
14
+ value = max;
15
+ }
16
+ return (value * 100) / max;
17
+ };
18
+
19
+ return (
20
+ <RPGUIRoot>
21
+ <Container
22
+ className="rpgui-progress"
23
+ data-value={calculatePercentageValue(max, value) / 100}
24
+ data-rpguitype="progress"
25
+ >
26
+ <div className=" rpgui-progress-track">
27
+ <div
28
+ className={`rpgui-progress-fill ${color} `}
29
+ style={{
30
+ left: '0px',
31
+ width: calculatePercentageValue(max, value) + '%',
32
+ }}
33
+ ></div>
34
+ </div>
35
+ <div className=" rpgui-progress-left-edge"></div>
36
+ <div className=" rpgui-progress-right-edge"></div>
37
+ </Container>
38
+ </RPGUIRoot>
39
+ );
40
+ };
41
+
42
+ const Container = styled.div`
43
+ display: flex;
44
+ flex-direction: column;
45
+ width: 20%;
46
+ justify-content: start;
47
+ align-items: flex-start;
48
+ `;
@@ -0,0 +1,53 @@
1
+ import React, { useEffect, useState } from 'react';
2
+
3
+ export interface IRadioItems {
4
+ label: string;
5
+ value: string;
6
+ }
7
+
8
+ export interface IRadioProps {
9
+ name: string;
10
+ items: IRadioItems[];
11
+ onChange: (value: string) => void;
12
+ }
13
+
14
+ export const InputRadio: React.FC<IRadioProps> = ({
15
+ name,
16
+ items,
17
+ onChange,
18
+ }) => {
19
+ const [selectedValue, setSelectedValue] = useState<string>();
20
+ const handleClick = () => {
21
+ let element = document.querySelector(
22
+ `input[name=${name}]:checked`
23
+ ) as HTMLInputElement;
24
+ const elementValue = element.value;
25
+ setSelectedValue(elementValue);
26
+ };
27
+
28
+ useEffect(() => {
29
+ if (selectedValue) {
30
+ onChange(selectedValue);
31
+ }
32
+ }, [selectedValue]);
33
+
34
+ return (
35
+ <div id="elemento-radio">
36
+ {items.map((element) => {
37
+ return (
38
+ <>
39
+ <input
40
+ key={element.value}
41
+ className="rpgui-radio"
42
+ value={element.value}
43
+ name={name}
44
+ type="radio"
45
+ />
46
+ <label onClick={handleClick}>{element.label}</label>
47
+ <br />
48
+ </>
49
+ );
50
+ })}
51
+ </div>
52
+ );
53
+ };
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+
3
+ export interface ITextArea
4
+ extends React.DetailedHTMLProps<
5
+ React.TextareaHTMLAttributes<HTMLTextAreaElement>,
6
+ HTMLTextAreaElement
7
+ > {}
8
+
9
+ export const TextArea: React.FC<ITextArea> = ({ ...props }) => {
10
+ return <textarea {...props} />;
11
+ };
@@ -0,0 +1,25 @@
1
+ /* eslint-disable react/require-default-props */
2
+ import React from 'react';
3
+ import styled from 'styled-components';
4
+
5
+ interface IProps {
6
+ maxLines?: number;
7
+ children: React.ReactNode;
8
+ }
9
+
10
+ export const Truncate: React.FC<IProps> = ({ maxLines = 1, children }) => {
11
+ return <Container maxLines={maxLines}>{children}</Container>;
12
+ };
13
+
14
+ interface IContainerProps {
15
+ maxLines: number;
16
+ }
17
+
18
+ const Container = styled.div<IContainerProps>`
19
+ display: -webkit-box;
20
+ max-width: 100%;
21
+ max-height: 100%;
22
+ -webkit-line-clamp: ${(props) => props.maxLines};
23
+ -webkit-box-orient: vertical;
24
+ overflow: hidden;
25
+ `;
package/src/index.tsx CHANGED
@@ -1,9 +1,15 @@
1
1
  export * from './components/Button';
2
+ export * from './components/CheckButton';
3
+ export * from './components/Dropdown';
4
+ export * from './components/Input';
2
5
  export * from './components/ListMenu';
3
6
  export * from './components/NPCDialog/NPCDialog';
4
7
  export * from './components/NPCDialog/QuestionDialog/QuestionDialog';
8
+ export * from './components/RadioButton';
5
9
  export * from './components/RangeSlider';
6
10
  export * from './components/RPGUIContainer';
7
11
  export * from './components/RPGUIRoot';
12
+ export * from './components/TextArea';
13
+ export * from './components/Truncate';
8
14
  export * from './components/typography/DynamicText';
9
15
  export { useEventListener } from './hooks/useEventListener';