@rpg-engine/long-bow 0.1.794 → 0.2.0

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 (129) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +181 -181
  3. package/dist/components/Button.d.ts +1 -0
  4. package/dist/components/Equipment/EquipmentSet.d.ts +5 -3
  5. package/dist/components/Item/Cards/ItemTooltip.d.ts +6 -0
  6. package/dist/components/Item/Inventory/ItemContainer.d.ts +4 -6
  7. package/dist/components/Item/Inventory/ItemContainerTypes.d.ts +6 -0
  8. package/dist/components/Item/Inventory/ItemSlot.d.ts +5 -9
  9. package/dist/components/Item/Inventory/itemContainerHelper.d.ts +2 -7
  10. package/dist/components/PropertySelect/PropertySelect.d.ts +12 -0
  11. package/dist/components/QuestInfo/QuestInfo.d.ts +14 -0
  12. package/dist/components/RelativeListMenu.d.ts +13 -0
  13. package/dist/index.d.ts +1 -1
  14. package/dist/long-bow.cjs.development.js +738 -1194
  15. package/dist/long-bow.cjs.development.js.map +1 -1
  16. package/dist/long-bow.cjs.production.min.js +1 -1
  17. package/dist/long-bow.cjs.production.min.js.map +1 -1
  18. package/dist/long-bow.esm.js +738 -1196
  19. package/dist/long-bow.esm.js.map +1 -1
  20. package/dist/mocks/equipmentSet.mocks.d.ts +2 -2
  21. package/dist/stories/Button.stories.d.ts +5 -0
  22. package/dist/stories/Chat.stories.d.ts +5 -0
  23. package/dist/stories/CheckButton.stories.d.ts +5 -0
  24. package/dist/stories/DraggableContainer.stories.d.ts +5 -0
  25. package/dist/stories/Dropdown.stories.d.ts +5 -0
  26. package/dist/stories/EquipmentSet.stories.d.ts +5 -0
  27. package/dist/stories/ItemContainer.stories.d.ts +5 -0
  28. package/dist/stories/ListMenu.stories.d.ts +5 -0
  29. package/dist/stories/Multitab.stories.d.ts +6 -0
  30. package/dist/stories/NPCDialog.stories.d.ts +7 -0
  31. package/dist/stories/ProgressBar.stories.d.ts +8 -0
  32. package/dist/stories/PropertySelect.stories.d.ts +5 -0
  33. package/dist/stories/QuestInfo.stories.d.ts +5 -0
  34. package/dist/stories/RPGUIContainers.stories.d.ts +5 -0
  35. package/dist/stories/RadioButton.stories.d.ts +5 -0
  36. package/dist/stories/RangeSlider.stories.d.ts +5 -0
  37. package/dist/stories/ScrollList.stories.d.ts +5 -0
  38. package/dist/stories/SimpleProgressBar.stories.d.ts +5 -0
  39. package/dist/stories/SkillProgressBar.stories.d.ts +5 -0
  40. package/dist/stories/SkillsContainer.stories.d.ts +5 -0
  41. package/dist/stories/Text.stories.d.ts +7 -0
  42. package/package.json +98 -96
  43. package/src/components/Abstractions/SlotsContainer.tsx +42 -42
  44. package/src/components/Button.tsx +30 -29
  45. package/src/components/Chat/Chat.tsx +193 -193
  46. package/src/components/CheckButton.tsx +65 -65
  47. package/src/components/DraggableContainer.tsx +150 -150
  48. package/src/components/Dropdown.tsx +57 -57
  49. package/src/components/Equipment/EquipmentSet.tsx +138 -180
  50. package/src/components/Input.tsx +11 -11
  51. package/src/components/Item/Cards/ItemTooltip.tsx +32 -0
  52. package/src/components/Item/Inventory/ItemContainer.tsx +68 -113
  53. package/src/components/Item/Inventory/ItemContainerTypes.ts +6 -0
  54. package/src/components/Item/Inventory/ItemSlot.tsx +212 -158
  55. package/src/components/Item/Inventory/itemContainerHelper.ts +133 -81
  56. package/src/components/ListMenu.tsx +65 -65
  57. package/src/components/Multitab/Tab.tsx +57 -57
  58. package/src/components/Multitab/TabBody.tsx +13 -13
  59. package/src/components/Multitab/TabsContainer.tsx +97 -97
  60. package/src/components/NPCDialog/NPCDialog.tsx +145 -145
  61. package/src/components/NPCDialog/NPCDialogText.tsx +53 -53
  62. package/src/components/NPCDialog/QuestionDialog/QuestionDialog.tsx +237 -242
  63. package/src/components/ProgressBar.tsx +91 -91
  64. package/src/components/PropertySelect/PropertySelect.tsx +101 -0
  65. package/src/components/PropertySelect/img/ui-arrows/arrow01-left-clicked.png +0 -0
  66. package/src/components/PropertySelect/img/ui-arrows/arrow01-left.png +0 -0
  67. package/src/components/PropertySelect/img/ui-arrows/arrow01-right-clicked.png +0 -0
  68. package/src/components/PropertySelect/img/ui-arrows/arrow01-right.png +0 -0
  69. package/src/components/PropertySelect/img/ui-arrows/arrow02-left-clicked.png +0 -0
  70. package/src/components/PropertySelect/img/ui-arrows/arrow02-left.png +0 -0
  71. package/src/components/PropertySelect/img/ui-arrows/arrow02-right-clicked.png +0 -0
  72. package/src/components/PropertySelect/img/ui-arrows/arrow02-right.png +0 -0
  73. package/src/components/QuestInfo/QuestInfo.tsx +143 -0
  74. package/src/components/QuestInfo/img/default.png +0 -0
  75. package/src/components/RPGUIContainer.tsx +47 -47
  76. package/src/components/RPGUIRoot.tsx +14 -14
  77. package/src/components/RadioButton.tsx +53 -53
  78. package/src/components/RangeSlider.tsx +68 -68
  79. package/src/components/RelativeListMenu.tsx +83 -0
  80. package/src/components/ScrollList.tsx +77 -77
  81. package/src/components/SimpleProgressBar.tsx +62 -62
  82. package/src/components/SkillProgressBar.tsx +123 -124
  83. package/src/components/SkillsContainer.tsx +196 -235
  84. package/src/components/TextArea.tsx +11 -11
  85. package/src/components/Truncate.tsx +25 -25
  86. package/src/components/shared/Column.tsx +16 -16
  87. package/src/components/shared/SpriteFromAtlas.tsx +99 -99
  88. package/src/components/typography/DynamicText.tsx +49 -49
  89. package/src/constants/uiColors.ts +10 -10
  90. package/src/hooks/useEventListener.ts +21 -21
  91. package/src/hooks/useOutsideAlerter.ts +25 -25
  92. package/src/index.tsx +25 -25
  93. package/src/libs/StringHelpers.ts +3 -3
  94. package/src/mocks/atlas/icons/icons.json +735 -303
  95. package/src/mocks/atlas/icons/icons.png +0 -0
  96. package/src/mocks/atlas/items/items.json +5215 -5195
  97. package/src/mocks/atlas/items/items.png +0 -0
  98. package/src/mocks/equipmentSet.mocks.ts +347 -347
  99. package/src/mocks/itemContainer.mocks.ts +249 -249
  100. package/src/mocks/skills.mocks.ts +122 -122
  101. package/src/stories/Button.stories.tsx +36 -0
  102. package/src/stories/Chat.stories.tsx +170 -0
  103. package/src/stories/CheckButton.stories.tsx +48 -0
  104. package/src/stories/DraggableContainer.stories.tsx +28 -0
  105. package/src/stories/Dropdown.stories.tsx +46 -0
  106. package/src/stories/EquipmentSet.stories.tsx +51 -0
  107. package/src/stories/ItemContainer.stories.tsx +51 -0
  108. package/src/stories/ListMenu.stories.tsx +56 -0
  109. package/src/stories/Multitab.stories.tsx +51 -0
  110. package/src/stories/NPCDialog.stories.tsx +130 -0
  111. package/src/stories/ProgressBar.stories.tsx +23 -0
  112. package/src/stories/PropertySelect.stories.tsx +41 -0
  113. package/src/stories/QuestInfo.stories.tsx +76 -0
  114. package/src/stories/RPGUIContainers.stories.tsx +42 -0
  115. package/src/stories/RadioButton.stories.tsx +49 -0
  116. package/src/stories/RangeSlider.stories.tsx +60 -0
  117. package/src/stories/ScrollList.stories.tsx +85 -0
  118. package/src/stories/SimpleProgressBar.stories.tsx +22 -0
  119. package/src/stories/SkillProgressBar.stories.tsx +30 -0
  120. package/src/stories/SkillsContainer.stories.tsx +31 -0
  121. package/src/stories/Text.stories.tsx +42 -0
  122. package/src/types/eventTypes.ts +4 -4
  123. package/src/types/index.d.ts +2 -2
  124. package/dist/components/Item/Cards/ItemCard.d.ts +0 -9
  125. package/dist/components/shared/SpriteIcon.d.ts +0 -9
  126. package/dist/components/store/UI.store.d.ts +0 -38
  127. package/src/components/Item/Cards/ItemCard.tsx +0 -36
  128. package/src/components/shared/SpriteIcon.tsx +0 -67
  129. package/src/components/store/UI.store.ts +0 -232
@@ -1,242 +1,237 @@
1
- import React, { useEffect, useState } from 'react';
2
- import styled from 'styled-components';
3
- import { useEventListener } from '../../../hooks/useEventListener';
4
- import { DynamicText } from '../../typography/DynamicText';
5
-
6
- export interface IQuestionDialogAnswer {
7
- id: number;
8
- text: string;
9
- nextQuestionId?: number;
10
- }
11
-
12
- export interface IQuestionDialog {
13
- id: number;
14
- text: string;
15
- answerIds?: number[];
16
- }
17
-
18
- export interface IProps {
19
- questions: IQuestionDialog[];
20
- answers: IQuestionDialogAnswer[];
21
- onClose: () => void;
22
- }
23
-
24
- export const QuestionDialog: React.FC<IProps> = ({
25
- questions,
26
- answers,
27
- onClose,
28
- }) => {
29
- const [currentQuestion, setCurrentQuestion] = useState(questions[0]);
30
-
31
- const [canShowAnswers, setCanShowAnswers] = useState<boolean>(false);
32
-
33
- const onGetFirstAnswer = () => {
34
- if (!currentQuestion.answerIds || currentQuestion.answerIds.length === 0) {
35
- return null;
36
- }
37
-
38
- const firstAnswerId = currentQuestion.answerIds![0];
39
-
40
- return answers.find(answer => answer.id === firstAnswerId);
41
- };
42
-
43
- const [
44
- currentAnswer,
45
- setCurrentAnswer,
46
- ] = useState<IQuestionDialogAnswer | null>(onGetFirstAnswer()!);
47
-
48
- useEffect(() => {
49
- setCurrentAnswer(onGetFirstAnswer()!);
50
- }, [currentQuestion]);
51
-
52
- const onGetAnswers = (answerIds: number[]) => {
53
- return answerIds.map((answerId: number) =>
54
- answers.find(answer => answer.id === answerId)
55
- );
56
- };
57
-
58
- const onKeyPress = (e: KeyboardEvent) => {
59
- switch (e.key) {
60
- case 'ArrowDown':
61
- // select next answer, if any.
62
- // if no next answer, select first answer
63
- // const nextAnswer = onGetAnswers(currentQuestion.answerIds!).find(
64
- // (answer) => answer?.id === currentAnswer!.id + 1
65
- // );
66
-
67
- const nextAnswerIndex = onGetAnswers(
68
- currentQuestion.answerIds!
69
- ).findIndex(answer => answer?.id === currentAnswer!.id + 1);
70
-
71
- const nextAnswerID = currentQuestion.answerIds![nextAnswerIndex];
72
-
73
- // console.log(nextAnswerIndex);
74
-
75
- const nextAnswer = onGetAnswers(currentQuestion.answerIds!).find(
76
- answer => answer?.id === nextAnswerID
77
- );
78
-
79
- setCurrentAnswer(nextAnswer || onGetFirstAnswer()!);
80
-
81
- break;
82
- case 'ArrowUp':
83
- // select previous answer, if any.
84
- // if no previous answer, select last answer
85
-
86
- const previousAnswerIndex = onGetAnswers(
87
- currentQuestion.answerIds!
88
- ).findIndex(answer => answer?.id === currentAnswer!.id - 1);
89
-
90
- const previousAnswerID =
91
- currentQuestion.answerIds &&
92
- currentQuestion.answerIds[previousAnswerIndex];
93
-
94
- const previousAnswer = onGetAnswers(currentQuestion.answerIds!).find(
95
- answer => answer?.id === previousAnswerID
96
- );
97
-
98
- if (previousAnswer) {
99
- setCurrentAnswer(previousAnswer);
100
- } else {
101
- setCurrentAnswer(onGetAnswers(currentQuestion.answerIds!).pop()!);
102
- }
103
-
104
- break;
105
- case 'Enter':
106
- setCanShowAnswers(false);
107
-
108
- if (!currentAnswer?.nextQuestionId) {
109
- onClose();
110
- return;
111
- } else {
112
- setCurrentQuestion(
113
- questions.find(
114
- question => question.id === currentAnswer!.nextQuestionId
115
- )!
116
- );
117
- }
118
-
119
- break;
120
- }
121
- };
122
- useEventListener('keydown', onKeyPress);
123
-
124
- const onAnswerClick = (answer: IQuestionDialogAnswer) => {
125
- setCanShowAnswers(false);
126
- if (answer.nextQuestionId) {
127
- // if there is a next question, go to it
128
- setCurrentQuestion(
129
- questions.find(question => question.id === answer.nextQuestionId)!
130
- );
131
- } else {
132
- // else, finish dialog!
133
- onClose();
134
- }
135
- };
136
-
137
- const onRenderCurrentAnswers = () => {
138
- const answerIds = currentQuestion.answerIds;
139
- if (!answerIds) {
140
- return null;
141
- }
142
-
143
- const answers = onGetAnswers(answerIds);
144
-
145
- if (!answers) {
146
- return null;
147
- }
148
-
149
- return answers.map(answer => {
150
- const isSelected = currentAnswer?.id === answer?.id;
151
- const selectedColor = isSelected ? 'yellow' : 'white';
152
-
153
- if (answer) {
154
- return (
155
- <AnswerRow key={`answer_${answer.id}`}>
156
- <AnswerSelectedIcon color={selectedColor}>
157
- {isSelected ? 'X' : null}
158
- </AnswerSelectedIcon>
159
-
160
- <Answer
161
- key={answer.id}
162
- onClick={() => onAnswerClick(answer)}
163
- color={selectedColor}
164
- >
165
- {answer.text}
166
- </Answer>
167
- </AnswerRow>
168
- );
169
- }
170
-
171
- return null;
172
- });
173
- };
174
-
175
- return (
176
- <Container>
177
- <QuestionContainer>
178
- <DynamicText
179
- text={currentQuestion.text}
180
- onStart={() => setCanShowAnswers(false)}
181
- onFinish={() => setCanShowAnswers(true)}
182
- />
183
- </QuestionContainer>
184
-
185
- {canShowAnswers && (
186
- <AnswersContainer>{onRenderCurrentAnswers()}</AnswersContainer>
187
- )}
188
- </Container>
189
- );
190
- };
191
-
192
- const Container = styled.div`
193
- display: flex;
194
-
195
- word-break: break-all;
196
-
197
- box-sizing: border-box;
198
- justify-content: flex-start;
199
- align-items: flex-start;
200
- flex-wrap: wrap;
201
- `;
202
-
203
- const QuestionContainer = styled.div`
204
- flex: 100%;
205
- width: 100%;
206
- `;
207
-
208
- const AnswersContainer = styled.div`
209
- flex: 100%;
210
- `;
211
-
212
- interface IAnswerProps {
213
- color: string;
214
- }
215
-
216
- const Answer = styled.p<IAnswerProps>`
217
- flex: auto;
218
- color: ${props => props.color} !important;
219
- font-size: 0.65rem !important;
220
- background: inherit;
221
- border: none;
222
- `;
223
-
224
- const AnswerSelectedIcon = styled.span<IAnswerProps>`
225
- flex: 5% 0 0;
226
- color: ${props => props.color} !important;
227
- `;
228
-
229
- const AnswerRow = styled.div`
230
- display: flex;
231
- flex-wrap: wrap;
232
- justify-content: center;
233
- align-items: center;
234
- margin-bottom: 0.5rem;
235
- height: 22px;
236
-
237
- p {
238
- line-height: unset;
239
- margin-top: 0;
240
- margin-bottom: 0rem;
241
- }
242
- `;
1
+ import React, { useEffect, useState } from 'react';
2
+ import styled from 'styled-components';
3
+ import { useEventListener } from '../../../hooks/useEventListener';
4
+ import { DynamicText } from '../../typography/DynamicText';
5
+
6
+ export interface IQuestionDialogAnswer {
7
+ id: number;
8
+ text: string;
9
+ nextQuestionId?: number;
10
+ }
11
+
12
+ export interface IQuestionDialog {
13
+ id: number;
14
+ text: string;
15
+ answerIds?: number[];
16
+ }
17
+
18
+ export interface IProps {
19
+ questions: IQuestionDialog[];
20
+ answers: IQuestionDialogAnswer[];
21
+ onClose: () => void;
22
+ }
23
+
24
+ export const QuestionDialog: React.FC<IProps> = ({
25
+ questions,
26
+ answers,
27
+ onClose,
28
+ }) => {
29
+ const [currentQuestion, setCurrentQuestion] = useState(questions[0]);
30
+
31
+ const [canShowAnswers, setCanShowAnswers] = useState<boolean>(false);
32
+
33
+ const onGetFirstAnswer = () => {
34
+ if (!currentQuestion.answerIds || currentQuestion.answerIds.length === 0) {
35
+ return null;
36
+ }
37
+
38
+ const firstAnswerId = currentQuestion.answerIds![0];
39
+
40
+ return answers.find(answer => answer.id === firstAnswerId);
41
+ };
42
+
43
+ const [
44
+ currentAnswer,
45
+ setCurrentAnswer,
46
+ ] = useState<IQuestionDialogAnswer | null>(onGetFirstAnswer()!);
47
+
48
+ useEffect(() => {
49
+ setCurrentAnswer(onGetFirstAnswer()!);
50
+ }, [currentQuestion]);
51
+
52
+ const onGetAnswers = (answerIds: number[]) => {
53
+ return answerIds.map((answerId: number) =>
54
+ answers.find(answer => answer.id === answerId)
55
+ );
56
+ };
57
+
58
+ const onKeyPress = (e: KeyboardEvent) => {
59
+ switch (e.key) {
60
+ case 'ArrowDown':
61
+ // select next answer, if any.
62
+ // if no next answer, select first answer
63
+ // const nextAnswer = onGetAnswers(currentQuestion.answerIds!).find(
64
+ // (answer) => answer?.id === currentAnswer!.id + 1
65
+ // );
66
+
67
+ const nextAnswerIndex = onGetAnswers(
68
+ currentQuestion.answerIds!
69
+ ).findIndex(answer => answer?.id === currentAnswer!.id + 1);
70
+
71
+ const nextAnswerID = currentQuestion.answerIds![nextAnswerIndex];
72
+
73
+ const nextAnswer = onGetAnswers(currentQuestion.answerIds!).find(
74
+ answer => answer?.id === nextAnswerID
75
+ );
76
+
77
+ setCurrentAnswer(nextAnswer || onGetFirstAnswer()!);
78
+
79
+ break;
80
+ case 'ArrowUp':
81
+ // select previous answer, if any.
82
+ // if no previous answer, select last answer
83
+
84
+ const previousAnswerIndex = onGetAnswers(
85
+ currentQuestion.answerIds!
86
+ ).findIndex(answer => answer?.id === currentAnswer!.id - 1);
87
+
88
+ const previousAnswerID =
89
+ currentQuestion.answerIds &&
90
+ currentQuestion.answerIds[previousAnswerIndex];
91
+
92
+ const previousAnswer = onGetAnswers(currentQuestion.answerIds!).find(
93
+ answer => answer?.id === previousAnswerID
94
+ );
95
+
96
+ if (previousAnswer) {
97
+ setCurrentAnswer(previousAnswer);
98
+ } else {
99
+ setCurrentAnswer(onGetAnswers(currentQuestion.answerIds!).pop()!);
100
+ }
101
+
102
+ break;
103
+ case 'Enter':
104
+ setCanShowAnswers(false);
105
+
106
+ if (!currentAnswer?.nextQuestionId) {
107
+ onClose();
108
+ return;
109
+ } else {
110
+ setCurrentQuestion(
111
+ questions.find(
112
+ question => question.id === currentAnswer!.nextQuestionId
113
+ )!
114
+ );
115
+ }
116
+
117
+ break;
118
+ }
119
+ };
120
+ useEventListener('keydown', onKeyPress);
121
+
122
+ const onAnswerClick = (answer: IQuestionDialogAnswer) => {
123
+ setCanShowAnswers(false);
124
+ if (answer.nextQuestionId) {
125
+ // if there is a next question, go to it
126
+ setCurrentQuestion(
127
+ questions.find(question => question.id === answer.nextQuestionId)!
128
+ );
129
+ } else {
130
+ // else, finish dialog!
131
+ onClose();
132
+ }
133
+ };
134
+
135
+ const onRenderCurrentAnswers = () => {
136
+ const answerIds = currentQuestion.answerIds;
137
+ if (!answerIds) {
138
+ return null;
139
+ }
140
+
141
+ const answers = onGetAnswers(answerIds);
142
+
143
+ if (!answers) {
144
+ return null;
145
+ }
146
+
147
+ return answers.map(answer => {
148
+ const isSelected = currentAnswer?.id === answer?.id;
149
+ const selectedColor = isSelected ? 'yellow' : 'white';
150
+
151
+ if (answer) {
152
+ return (
153
+ <AnswerRow key={`answer_${answer.id}`}>
154
+ <AnswerSelectedIcon color={selectedColor}>
155
+ {isSelected ? 'X' : null}
156
+ </AnswerSelectedIcon>
157
+
158
+ <Answer
159
+ key={answer.id}
160
+ onClick={() => onAnswerClick(answer)}
161
+ color={selectedColor}
162
+ >
163
+ {answer.text}
164
+ </Answer>
165
+ </AnswerRow>
166
+ );
167
+ }
168
+
169
+ return null;
170
+ });
171
+ };
172
+
173
+ return (
174
+ <Container>
175
+ <QuestionContainer>
176
+ <DynamicText
177
+ text={currentQuestion.text}
178
+ onStart={() => setCanShowAnswers(false)}
179
+ onFinish={() => setCanShowAnswers(true)}
180
+ />
181
+ </QuestionContainer>
182
+
183
+ {canShowAnswers && (
184
+ <AnswersContainer>{onRenderCurrentAnswers()}</AnswersContainer>
185
+ )}
186
+ </Container>
187
+ );
188
+ };
189
+
190
+ const Container = styled.div`
191
+ display: flex;
192
+ word-break: break-all;
193
+ box-sizing: border-box;
194
+ justify-content: flex-start;
195
+ align-items: flex-start;
196
+ flex-wrap: wrap;
197
+ `;
198
+
199
+ const QuestionContainer = styled.div`
200
+ flex: 100%;
201
+ width: 100%;
202
+ `;
203
+
204
+ const AnswersContainer = styled.div`
205
+ flex: 100%;
206
+ `;
207
+
208
+ interface IAnswerProps {
209
+ color: string;
210
+ }
211
+
212
+ const Answer = styled.p<IAnswerProps>`
213
+ flex: auto;
214
+ color: ${props => props.color} !important;
215
+ font-size: 0.65rem !important;
216
+ background: inherit;
217
+ border: none;
218
+ `;
219
+
220
+ const AnswerSelectedIcon = styled.span<IAnswerProps>`
221
+ flex: 5% 0 0;
222
+ color: ${props => props.color} !important;
223
+ `;
224
+
225
+ const AnswerRow = styled.div`
226
+ display: flex;
227
+ flex-wrap: wrap;
228
+ justify-content: center;
229
+ align-items: center;
230
+ margin-bottom: 0.5rem;
231
+ height: 22px;
232
+ p {
233
+ line-height: unset;
234
+ margin-top: 0;
235
+ margin-bottom: 0rem;
236
+ }
237
+ `;
@@ -1,91 +1,91 @@
1
- import React from 'react';
2
- import styled from 'styled-components';
3
-
4
- export interface IBarProps {
5
- max: number;
6
- value: number;
7
- color: 'red' | 'blue' | 'green';
8
- style?: Record<string, any>;
9
- displayText?: boolean;
10
- percentageWidth?: number;
11
- minWidth?: number;
12
- }
13
-
14
- export const ProgressBar: React.FC<IBarProps> = ({
15
- max,
16
- value,
17
- color,
18
- displayText = true,
19
- percentageWidth = 40,
20
- minWidth = 100,
21
- style,
22
- }) => {
23
- const calculatePercentageValue = function(max: number, value: number) {
24
- if (value > max) {
25
- value = max;
26
- }
27
- return (value * 100) / max;
28
- };
29
-
30
- return (
31
- <Container
32
- className="rpgui-progress"
33
- data-value={calculatePercentageValue(max, value) / 100}
34
- data-rpguitype="progress"
35
- percentageWidth={percentageWidth}
36
- minWidth={minWidth}
37
- style={style}
38
- >
39
- {displayText && (
40
- <TextOverlay>
41
- <ProgressBarText>
42
- {value}/{max}
43
- </ProgressBarText>
44
- </TextOverlay>
45
- )}
46
- <div className=" rpgui-progress-track">
47
- <div
48
- className={`rpgui-progress-fill ${color} `}
49
- style={{
50
- left: '0px',
51
- width: calculatePercentageValue(max, value) + '%',
52
- }}
53
- ></div>
54
- </div>
55
- <div className=" rpgui-progress-left-edge"></div>
56
- <div className=" rpgui-progress-right-edge"></div>
57
- </Container>
58
- );
59
- };
60
-
61
- const ProgressBarText = styled.span`
62
- font-size: 1rem;
63
- color: white;
64
- text-align: center;
65
- z-index: 1;
66
- position: absolute;
67
- left: 50%;
68
- transform: translateX(-50%);
69
- top: 12px;
70
- `;
71
-
72
- const TextOverlay = styled.div`
73
- width: 100%;
74
- position: relative;
75
- `;
76
-
77
- interface IContainerProps {
78
- percentageWidth?: number;
79
- minWidth?: number;
80
- style?: Record<string, any>;
81
- }
82
-
83
- const Container = styled.div<IContainerProps>`
84
- display: flex;
85
- flex-direction: column;
86
- min-width: ${props => props.minWidth}px;
87
- width: ${props => props.percentageWidth}%;
88
- justify-content: start;
89
- align-items: flex-start;
90
- ${props => props.style}
91
- `;
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ export interface IBarProps {
5
+ max: number;
6
+ value: number;
7
+ color: 'red' | 'blue' | 'green';
8
+ style?: Record<string, any>;
9
+ displayText?: boolean;
10
+ percentageWidth?: number;
11
+ minWidth?: number;
12
+ }
13
+
14
+ export const ProgressBar: React.FC<IBarProps> = ({
15
+ max,
16
+ value,
17
+ color,
18
+ displayText = true,
19
+ percentageWidth = 40,
20
+ minWidth = 100,
21
+ style,
22
+ }) => {
23
+ const calculatePercentageValue = function(max: number, value: number) {
24
+ if (value > max) {
25
+ value = max;
26
+ }
27
+ return (value * 100) / max;
28
+ };
29
+
30
+ return (
31
+ <Container
32
+ className="rpgui-progress"
33
+ data-value={calculatePercentageValue(max, value) / 100}
34
+ data-rpguitype="progress"
35
+ percentageWidth={percentageWidth}
36
+ minWidth={minWidth}
37
+ style={style}
38
+ >
39
+ {displayText && (
40
+ <TextOverlay>
41
+ <ProgressBarText>
42
+ {value}/{max}
43
+ </ProgressBarText>
44
+ </TextOverlay>
45
+ )}
46
+ <div className=" rpgui-progress-track">
47
+ <div
48
+ className={`rpgui-progress-fill ${color} `}
49
+ style={{
50
+ left: '0px',
51
+ width: calculatePercentageValue(max, value) + '%',
52
+ }}
53
+ ></div>
54
+ </div>
55
+ <div className=" rpgui-progress-left-edge"></div>
56
+ <div className=" rpgui-progress-right-edge"></div>
57
+ </Container>
58
+ );
59
+ };
60
+
61
+ const ProgressBarText = styled.span`
62
+ font-size: 1rem;
63
+ color: white;
64
+ text-align: center;
65
+ z-index: 1;
66
+ position: absolute;
67
+ left: 50%;
68
+ transform: translateX(-50%);
69
+ top: 12px;
70
+ `;
71
+
72
+ const TextOverlay = styled.div`
73
+ width: 100%;
74
+ position: relative;
75
+ `;
76
+
77
+ interface IContainerProps {
78
+ percentageWidth?: number;
79
+ minWidth?: number;
80
+ style?: Record<string, any>;
81
+ }
82
+
83
+ const Container = styled.div<IContainerProps>`
84
+ display: flex;
85
+ flex-direction: column;
86
+ min-width: ${props => props.minWidth}px;
87
+ width: ${props => props.percentageWidth}%;
88
+ justify-content: start;
89
+ align-items: flex-start;
90
+ ${props => props.style}
91
+ `;