Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/resources/scripts/components/elements/Input.tsx
7461 views
1
import styled, { css } from 'styled-components/macro';
2
import tw from 'twin.macro';
3
4
export interface Props {
5
isLight?: boolean;
6
hasError?: boolean;
7
}
8
9
const light = css<Props>`
10
${tw`bg-white border-neutral-200 text-neutral-800`};
11
&:focus {
12
${tw`border-primary-400`}
13
}
14
15
&:disabled {
16
${tw`bg-neutral-100 border-neutral-200`};
17
}
18
`;
19
20
const checkboxStyle = css<Props>`
21
${tw`bg-neutral-500 cursor-pointer appearance-none inline-block align-middle select-none flex-shrink-0 w-4 h-4 text-primary-400 border border-neutral-300 rounded-sm`};
22
color-adjust: exact;
23
background-origin: border-box;
24
transition: all 75ms linear, box-shadow 25ms linear;
25
26
&:checked {
27
${tw`border-transparent bg-no-repeat bg-center`};
28
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M5.707 7.293a1 1 0 0 0-1.414 1.414l2 2a1 1 0 0 0 1.414 0l4-4a1 1 0 0 0-1.414-1.414L7 8.586 5.707 7.293z'/%3e%3c/svg%3e");
29
background-color: currentColor;
30
background-size: 100% 100%;
31
}
32
33
&:focus {
34
${tw`outline-none border-primary-300`};
35
box-shadow: 0 0 0 1px rgba(9, 103, 210, 0.25);
36
}
37
`;
38
39
const inputStyle = css<Props>`
40
// Reset to normal styling.
41
resize: none;
42
${tw`appearance-none outline-none w-full min-w-0`};
43
${tw`p-3 border-2 rounded text-sm transition-all duration-150`};
44
${tw`bg-neutral-600 border-neutral-500 hover:border-neutral-400 text-neutral-200 shadow-none focus:ring-0`};
45
46
& + .input-help {
47
${tw`mt-1 text-xs`};
48
${(props) => (props.hasError ? tw`text-red-200` : tw`text-neutral-200`)};
49
}
50
51
&:required,
52
&:invalid {
53
${tw`shadow-none`};
54
}
55
56
&:not(:disabled):not(:read-only):focus {
57
${tw`shadow-md border-primary-300 ring-2 ring-primary-400 ring-opacity-50`};
58
${(props) => props.hasError && tw`border-red-300 ring-red-200`};
59
}
60
61
&:disabled {
62
${tw`opacity-75`};
63
}
64
65
${(props) => props.isLight && light};
66
${(props) => props.hasError && tw`text-red-100 border-red-400 hover:border-red-300`};
67
`;
68
69
const Input = styled.input<Props>`
70
&:not([type='checkbox']):not([type='radio']) {
71
${inputStyle};
72
}
73
74
&[type='checkbox'],
75
&[type='radio'] {
76
${checkboxStyle};
77
78
&[type='radio'] {
79
${tw`rounded-full`};
80
}
81
}
82
`;
83
const Textarea = styled.textarea<Props>`
84
${inputStyle}
85
`;
86
87
export { Textarea };
88
export default Input;
89
90