diff --git a/pages/index.js b/pages/index.js index 5ce6034e..d889dda7 100644 --- a/pages/index.js +++ b/pages/index.js @@ -31,6 +31,7 @@ export default function Playground() { const [newDisabledDates, setNewDisabledDates] = useState({ startDate: "", endDate: "" }); const [startFrom, setStartFrom] = useState("2023-03-01"); const [startWeekOn, setStartWeekOn] = useState(""); + const [inline, setInline] = useState(false); const handleChange = (value, e) => { setValue(value); @@ -113,6 +114,7 @@ export default function Playground() { return isEmpty ? "Select Date" : "Clear"; }} popoverDirection={"down"} + inline={inline} // classNames={{ // input: ({ disabled, readOnly, className }) => { // if (disabled) { @@ -215,6 +217,20 @@ export default function Playground() { +
+
+ setInline(e.target.checked)} + /> + +
+
diff --git a/src/components/Datepicker.tsx b/src/components/Datepicker.tsx index 54e90b78..3b5f5e36 100644 --- a/src/components/Datepicker.tsx +++ b/src/components/Datepicker.tsx @@ -7,13 +7,13 @@ import Input from "../components/Input"; import Shortcuts from "../components/Shortcuts"; import { COLORS, DATE_FORMAT, DEFAULT_COLOR, LANGUAGE } from "../constants"; import DatepickerContext from "../contexts/DatepickerContext"; -import { formatDate, nextMonth, previousMonth } from "../helpers"; +import { formatDate, nextMonth, previousMonth, classNames as classNamesUtil } from "../helpers"; import useOnClickOutside from "../hooks"; import { Period, DatepickerType, ColorKeys } from "../types"; import { Arrow, VerticalDash } from "./utils"; -const Datepicker: React.FC = ({ +const Datepicker = ({ primaryColor = "blue", value = null, onChange, @@ -22,13 +22,14 @@ const Datepicker: React.FC = ({ showShortcuts = false, configs = undefined, asSingle = false, - placeholder = null, + placeholder = undefined, separator = "~", startFrom = null, i18n = LANGUAGE, disabled = false, inputClassName = null, containerClassName = null, + pickerClassName = null, toggleClassName = null, toggleIcon = undefined, displayFormat = DATE_FORMAT, @@ -41,8 +42,9 @@ const Datepicker: React.FC = ({ inputName, startWeekOn = "sun", classNames = undefined, - popoverDirection = undefined -}) => { + popoverDirection = undefined, + inline = false +}: DatepickerType) => { // Ref const containerRef = useRef(null); const calendarContainerRef = useRef(null); @@ -64,7 +66,7 @@ const Datepicker: React.FC = ({ // Custom Hooks use useOnClickOutside(containerRef, () => { const container = containerRef.current; - if (container) { + if (container && !inline) { hideDatepicker(); } }); @@ -327,18 +329,33 @@ const Datepicker: React.FC = ({ : defaultContainerClassName; }, [containerClassName]); + const pickerClassNameOverload = useMemo(() => { + const defaultPickerClassName = classNamesUtil( + "shadow-sm border border-gray-300 px-1 py-0.5 bg-white dark:bg-slate-800 dark:text-white dark:border-slate-600 rounded-lg w-fit", + !inline && "mt-2.5" + ); + return typeof pickerClassName === "function" + ? pickerClassName(defaultPickerClassName) + : typeof pickerClassName === "string" && pickerClassName !== "" + ? pickerClassName + : defaultPickerClassName; + }, [pickerClassName, inline]); + return (
- + {!inline && }