Skip to content

Commit 3131204

Browse files
authored
fix: null properties (#497)
1 parent 82e6754 commit 3131204

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/pages/grid-generator.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,21 @@ function getCssOrTailwind(e?: MouseEvent): void {
6565

6666
closeDropdown(getCssOrTailwind, getCssOrTailwindDropdownElement, showCopyClass);
6767

68+
function doInputExist() {
69+
const noOfColumns = getNumberOfColumns(attribute);
70+
const noOfRows = getNumberOfRows(attribute);
71+
72+
if (!noOfColumns.value || !noOfRows.value) {
73+
showPopup("Couldn't Copy Code", 'Some input value may be missing', 'error');
74+
return false;
75+
}
76+
77+
return true;
78+
}
79+
6880
function copyTailwindHandler() {
6981
const outputElement: HTMLElement = getGridPreview(attribute);
82+
if (doInputExist() === false) return;
7083
copyTailwindCodeToClipboard(attribute, outputElement);
7184
showPopup(
7285
'Tailwind Code Copied',
@@ -77,6 +90,7 @@ function copyTailwindHandler() {
7790

7891
function copyCSSHandler() {
7992
const outputElement = getGridPreview(attribute);
93+
if (doInputExist() === false) return;
8094
copyCSSCodeToClipboard(attribute, outputElement);
8195
showPopup(
8296
'Code Copied',

src/pages/input-range.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,42 @@ function setPreview(values: Values): void {
123123
);
124124
}
125125

126+
function doInputsExist() {
127+
const getTrackColor = getColorInput1(attribute);
128+
const getThumbColor = getColorInput2(attribute);
129+
130+
const doColorInputsExist = getTrackColor.value && getThumbColor.value;
131+
132+
const trackCheckBox = getCheckbox(`${attribute}-track`);
133+
const getTrackRadius = getRadiusInput(`${attribute}-track`);
134+
135+
const doesTrackRadiusInputExists = trackCheckBox.checked
136+
? getTrackRadius.value !== ''
137+
: true;
138+
139+
const thumbCheckBox = getCheckbox(`${attribute}-thumb`);
140+
const getThumbRadius = getRadiusInput(`${attribute}-thumb`);
141+
142+
const doesThumbRadiusInputExists = thumbCheckBox.checked
143+
? getThumbRadius.value !== ''
144+
: true;
145+
146+
if (
147+
doColorInputsExist &&
148+
doesTrackRadiusInputExists &&
149+
doesThumbRadiusInputExists
150+
)
151+
return true;
152+
153+
showPopup("Couldn't Copy Code", 'Some input value may be missing', 'error');
154+
return false;
155+
}
156+
126157
function copyHandler() {
127158
const previewElement = document.getElementById(
128159
'preview-range'
129160
) as HTMLInputElement;
161+
if (doInputsExist() === false) return;
130162
copyCSSCodeToClipboard(attribute, previewElement);
131163
showPopup(
132164
'Code Copied',
@@ -254,6 +286,7 @@ getValues();
254286
// Tailwind codecopy handler
255287
function tailwindHandler() {
256288
const element = document.querySelector('#preview-range') as HTMLInputElement;
289+
if (doInputsExist() === false) return;
257290
copyTailwindCodeToClipboard(attribute, element);
258291
showPopup(
259292
'Tailwind Code Copied',

0 commit comments

Comments
 (0)