|
| 1 | +import Datepicker from "../src"; |
| 2 | +import { useState } from "react"; |
| 3 | +import { COLORS } from "../src/constants"; |
| 4 | +import dayjs from "dayjs"; |
| 5 | +import Head from "next/head"; |
| 6 | + |
| 7 | +export default function Playground() { |
| 8 | + const [value, setValue] = useState({ |
| 9 | + startDate: null, |
| 10 | + endDate: null |
| 11 | + }); |
| 12 | + const [primaryColor, setPrimaryColor] = useState("blue"); |
| 13 | + const [useRange, setUseRange] = useState(true); |
| 14 | + const [showFooter, setShowFooter] = useState(false); |
| 15 | + const [showShortcuts, setShowShortcuts] = useState(false); |
| 16 | + const [configs, setConfigs] = useState(null); |
| 17 | + const [asSingle, setAsSingle] = useState(false); |
| 18 | + const [placeholder, setPlaceholder] = useState(""); |
| 19 | + const [separator, setSeparator] = useState("~"); |
| 20 | + const [i18n, setI18n] = useState("en"); |
| 21 | + const [disabled, setDisabled] = useState(false); |
| 22 | + const [inputClassName, setInputClassName] = useState(""); |
| 23 | + const [containerClassName, setContainerClassName] = useState(""); |
| 24 | + const [displayFormat, setDisplayFormat] = useState("YYYY-MM-DD"); |
| 25 | + const [readOnly, setReadOnly] = useState(false); |
| 26 | + const [startFrom, setStartFrom] = useState("2023-03-01"); |
| 27 | + |
| 28 | + return ( |
| 29 | + <div className="px-4 py-8"> |
| 30 | + <Head> |
| 31 | + <title>react-tailwindcss-datepicker PlayGround</title> |
| 32 | + </Head> |
| 33 | + <h1 className="text-center font-semibold text-xl"> |
| 34 | + <pre className="text-gray-600 text-lg bg-gray-200 max-w-max mx-auto px-2 rounded"> |
| 35 | + react-tailwindcss-datepicker |
| 36 | + </pre> |
| 37 | + <span className="text-gray-700">PlayGround</span> |
| 38 | + </h1> |
| 39 | + |
| 40 | + <div className="max-w-md mx-auto my-4"> |
| 41 | + <Datepicker |
| 42 | + value={value} |
| 43 | + primaryColor={primaryColor} |
| 44 | + onChange={setValue} |
| 45 | + useRange={useRange} |
| 46 | + showFooter={showFooter} |
| 47 | + showShortcuts={showShortcuts} |
| 48 | + configs={configs} |
| 49 | + asSingle={asSingle} |
| 50 | + placeholder={placeholder} |
| 51 | + separator={separator} |
| 52 | + startFrom={ |
| 53 | + startFrom.length && dayjs(startFrom).isValid() ? new Date(startFrom) : null |
| 54 | + } |
| 55 | + i18n={i18n} |
| 56 | + disabled={disabled} |
| 57 | + inputClassName={inputClassName} |
| 58 | + containerClassName={containerClassName} |
| 59 | + displayFormat={displayFormat} |
| 60 | + readOnly={readOnly} |
| 61 | + /> |
| 62 | + </div> |
| 63 | + |
| 64 | + <div className="py-4 max-w-3xl mx-auto flex flex-row flex-wrap"> |
| 65 | + <div className="w-full sm:w-1/3 pr-2 flex flex-row flex-wrap sm:flex-col"> |
| 66 | + <div className="mb-2 w-1/2 sm:w-full"> |
| 67 | + <div className="inline-flex items-center"> |
| 68 | + <input |
| 69 | + type="checkbox" |
| 70 | + className="mr-2 rounded" |
| 71 | + id="useRange" |
| 72 | + checked={useRange} |
| 73 | + onChange={e => setUseRange(e.target.checked)} |
| 74 | + /> |
| 75 | + <label className="block" htmlFor="useRange"> |
| 76 | + Use Range |
| 77 | + </label> |
| 78 | + </div> |
| 79 | + </div> |
| 80 | + <div className="mb-2 w-1/2 sm:w-full"> |
| 81 | + <div className="inline-flex items-center"> |
| 82 | + <input |
| 83 | + type="checkbox" |
| 84 | + className="mr-2 rounded" |
| 85 | + id="showFooter" |
| 86 | + checked={showFooter} |
| 87 | + onChange={e => setShowFooter(e.target.checked)} |
| 88 | + /> |
| 89 | + <label className="block" htmlFor="showFooter"> |
| 90 | + Show Footer |
| 91 | + </label> |
| 92 | + </div> |
| 93 | + </div> |
| 94 | + <div className="mb-2 w-1/2 sm:w-full"> |
| 95 | + <div className="inline-flex items-center"> |
| 96 | + <input |
| 97 | + type="checkbox" |
| 98 | + className="mr-2 rounded" |
| 99 | + id="showShortcuts" |
| 100 | + checked={showShortcuts} |
| 101 | + onChange={e => setShowShortcuts(e.target.checked)} |
| 102 | + /> |
| 103 | + <label className="block" htmlFor="showShortcuts"> |
| 104 | + Show Shortcuts |
| 105 | + </label> |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + <div className="mb-2 w-1/2 sm:w-full"> |
| 109 | + <div className="inline-flex items-center"> |
| 110 | + <input |
| 111 | + type="checkbox" |
| 112 | + className="mr-2 rounded" |
| 113 | + id="asSingle" |
| 114 | + checked={asSingle} |
| 115 | + onChange={e => setAsSingle(e.target.checked)} |
| 116 | + /> |
| 117 | + <label className="block" htmlFor="asSingle"> |
| 118 | + As Single |
| 119 | + </label> |
| 120 | + </div> |
| 121 | + </div> |
| 122 | + <div className="mb-2 w-1/2 sm:w-full"> |
| 123 | + <div className="inline-flex items-center"> |
| 124 | + <input |
| 125 | + type="checkbox" |
| 126 | + className="mr-2 rounded" |
| 127 | + id="disabled" |
| 128 | + checked={disabled} |
| 129 | + onChange={e => setDisabled(e.target.checked)} |
| 130 | + /> |
| 131 | + <label className="block" htmlFor="disabled"> |
| 132 | + Disabled |
| 133 | + </label> |
| 134 | + </div> |
| 135 | + </div> |
| 136 | + <div className="mb-2 w-1/2 sm:w-full"> |
| 137 | + <div className="inline-flex items-center"> |
| 138 | + <input |
| 139 | + type="checkbox" |
| 140 | + className="mr-2 rounded" |
| 141 | + id="readOnly" |
| 142 | + checked={readOnly} |
| 143 | + onChange={e => setReadOnly(e.target.checked)} |
| 144 | + /> |
| 145 | + <label className="block" htmlFor="readOnly"> |
| 146 | + Read Only |
| 147 | + </label> |
| 148 | + </div> |
| 149 | + </div> |
| 150 | + </div> |
| 151 | + <div className="w-full sm:w-1/3 pr-2 flex flex-col"> |
| 152 | + <div className="mb-2"> |
| 153 | + <label className="block" htmlFor="primaryColor"> |
| 154 | + Primary Color |
| 155 | + </label> |
| 156 | + <select |
| 157 | + className="rounded block w-full border-gray-200 border px-4 py-2" |
| 158 | + id="primaryColor" |
| 159 | + value={primaryColor} |
| 160 | + onChange={e => { |
| 161 | + setPrimaryColor(e.target.value); |
| 162 | + }} |
| 163 | + > |
| 164 | + {COLORS.map((color, i) => ( |
| 165 | + <option key={i} value={color}> |
| 166 | + {color} |
| 167 | + </option> |
| 168 | + ))} |
| 169 | + </select> |
| 170 | + </div> |
| 171 | + <div className="mb-2"> |
| 172 | + <label className="block" htmlFor="placeholder"> |
| 173 | + Placeholder |
| 174 | + </label> |
| 175 | + <input |
| 176 | + className="rounded border px-4 py-2 w-full border-gray-200" |
| 177 | + id="placeholder" |
| 178 | + value={placeholder} |
| 179 | + onChange={e => { |
| 180 | + setPlaceholder(e.target.value); |
| 181 | + }} |
| 182 | + /> |
| 183 | + </div> |
| 184 | + <div className="mb-2"> |
| 185 | + <label className="block" htmlFor="separator"> |
| 186 | + Separator |
| 187 | + </label> |
| 188 | + <input |
| 189 | + className="rounded border px-4 py-2 w-full border-gray-200" |
| 190 | + id="separator" |
| 191 | + value={separator} |
| 192 | + onChange={e => { |
| 193 | + setSeparator(e.target.value); |
| 194 | + }} |
| 195 | + /> |
| 196 | + </div> |
| 197 | + <div className="mb-2"> |
| 198 | + <label className="block" htmlFor="startFrom"> |
| 199 | + Start From |
| 200 | + </label> |
| 201 | + <input |
| 202 | + className="rounded border px-4 py-2 w-full border-gray-200" |
| 203 | + id="startFrom" |
| 204 | + value={startFrom} |
| 205 | + onChange={e => { |
| 206 | + setStartFrom(e.target.value); |
| 207 | + }} |
| 208 | + /> |
| 209 | + </div> |
| 210 | + </div> |
| 211 | + <div className="w-full sm:w-1/3 pr-2 flex flex-col"> |
| 212 | + <div className="mb-2"> |
| 213 | + <label className="block" htmlFor="i18n"> |
| 214 | + i18n |
| 215 | + </label> |
| 216 | + <input |
| 217 | + className="rounded border px-4 py-2 w-full border-gray-200" |
| 218 | + id="i18n" |
| 219 | + value={i18n} |
| 220 | + onChange={e => { |
| 221 | + setI18n(e.target.value); |
| 222 | + }} |
| 223 | + /> |
| 224 | + </div> |
| 225 | + <div className="mb-2"> |
| 226 | + <label className="block" htmlFor="displayFormat"> |
| 227 | + Display Format |
| 228 | + </label> |
| 229 | + <input |
| 230 | + className="rounded border px-4 py-2 w-full border-gray-200" |
| 231 | + id="displayFormat" |
| 232 | + value={displayFormat} |
| 233 | + onChange={e => { |
| 234 | + setDisplayFormat(e.target.value); |
| 235 | + }} |
| 236 | + /> |
| 237 | + </div> |
| 238 | + <div className="mb-2"> |
| 239 | + <label className="block" htmlFor="inputClassName"> |
| 240 | + Input Class |
| 241 | + </label> |
| 242 | + <input |
| 243 | + className="rounded border px-4 py-2 w-full border-gray-200" |
| 244 | + id="inputClassName" |
| 245 | + value={inputClassName} |
| 246 | + onChange={e => { |
| 247 | + setInputClassName(e.target.value); |
| 248 | + }} |
| 249 | + /> |
| 250 | + </div> |
| 251 | + <div className="mb-2"> |
| 252 | + <label className="block" htmlFor="containerClassName"> |
| 253 | + Container Class |
| 254 | + </label> |
| 255 | + <input |
| 256 | + className="rounded border px-4 py-2 w-full border-gray-200" |
| 257 | + id="containerClassName" |
| 258 | + value={containerClassName} |
| 259 | + onChange={e => { |
| 260 | + setContainerClassName(e.target.value); |
| 261 | + }} |
| 262 | + /> |
| 263 | + </div> |
| 264 | + </div> |
| 265 | + </div> |
| 266 | + <div className="flex flex-row flex-wrap items-center justify-center w-full"> |
| 267 | + <a |
| 268 | + href="https://github.com/onesine/react-tailwindcss-datepicker" |
| 269 | + className="block text-gray-700 hover:text-gray-600" |
| 270 | + > |
| 271 | + <svg |
| 272 | + xmlns="http://www.w3.org/2000/svg" |
| 273 | + fill="currentColor" |
| 274 | + className="w-6 h-6" |
| 275 | + viewBox="0 0 16 16" |
| 276 | + > |
| 277 | + <path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z" /> |
| 278 | + </svg> |
| 279 | + </a> |
| 280 | + </div> |
| 281 | + </div> |
| 282 | + ); |
| 283 | +} |
0 commit comments