@xanui/ui 1.2.5 → 1.2.7
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.
- package/Accordion/index.cjs +5 -5
- package/Accordion/index.cjs.map +1 -1
- package/Accordion/index.d.ts +3 -3
- package/Accordion/index.js +5 -5
- package/Accordion/index.js.map +1 -1
- package/Alert/index.cjs +19 -17
- package/Alert/index.cjs.map +1 -1
- package/Alert/index.d.ts +4 -4
- package/Alert/index.js +19 -17
- package/Alert/index.js.map +1 -1
- package/Autocomplete/index.cjs +2 -2
- package/Autocomplete/index.cjs.map +1 -1
- package/Autocomplete/index.d.ts +7 -7
- package/Autocomplete/index.js +2 -2
- package/Autocomplete/index.js.map +1 -1
- package/Avatar/index.cjs +2 -2
- package/Avatar/index.cjs.map +1 -1
- package/Avatar/index.d.ts +2 -2
- package/Avatar/index.js +2 -2
- package/Avatar/index.js.map +1 -1
- package/AvatarBox/index.cjs +19 -0
- package/AvatarBox/index.cjs.map +1 -0
- package/AvatarBox/index.d.ts +19 -0
- package/AvatarBox/index.js +17 -0
- package/AvatarBox/index.js.map +1 -0
- package/AvatarPicker/index.cjs +80 -0
- package/AvatarPicker/index.cjs.map +1 -0
- package/AvatarPicker/index.d.ts +27 -0
- package/AvatarPicker/index.js +78 -0
- package/AvatarPicker/index.js.map +1 -0
- package/Badge/index.cjs +1 -1
- package/Badge/index.cjs.map +1 -1
- package/Badge/index.d.ts +4 -4
- package/Badge/index.js +1 -1
- package/Badge/index.js.map +1 -1
- package/Box/index.d.ts +2 -2
- package/Button/index.cjs +5 -3
- package/Button/index.cjs.map +1 -1
- package/Button/index.d.ts +2 -2
- package/Button/index.js +5 -3
- package/Button/index.js.map +1 -1
- package/ButtonGroup/index.cjs +3 -2
- package/ButtonGroup/index.cjs.map +1 -1
- package/ButtonGroup/index.d.ts +2 -2
- package/ButtonGroup/index.js +3 -2
- package/ButtonGroup/index.js.map +1 -1
- package/Calendar/index.cjs +10 -10
- package/Calendar/index.cjs.map +1 -1
- package/Calendar/index.js +10 -10
- package/Calendar/index.js.map +1 -1
- package/CalendarInput/index.cjs +1 -1
- package/CalendarInput/index.cjs.map +1 -1
- package/CalendarInput/index.js +1 -1
- package/CalendarInput/index.js.map +1 -1
- package/Carousel/index.cjs +231 -0
- package/Carousel/index.cjs.map +1 -0
- package/Carousel/index.d.ts +28 -0
- package/Carousel/index.js +229 -0
- package/Carousel/index.js.map +1 -0
- package/Checkbox/index.cjs +2 -2
- package/Checkbox/index.cjs.map +1 -1
- package/Checkbox/index.d.ts +2 -2
- package/Checkbox/index.js +2 -2
- package/Checkbox/index.js.map +1 -1
- package/Chip/index.cjs +3 -3
- package/Chip/index.cjs.map +1 -1
- package/Chip/index.d.ts +2 -2
- package/Chip/index.js +3 -3
- package/Chip/index.js.map +1 -1
- package/CircleProgress/index.cjs +10 -10
- package/CircleProgress/index.cjs.map +1 -1
- package/CircleProgress/index.d.ts +2 -2
- package/CircleProgress/index.js +10 -10
- package/CircleProgress/index.js.map +1 -1
- package/ClickOutside/index.cjs +3 -12
- package/ClickOutside/index.cjs.map +1 -1
- package/ClickOutside/index.d.ts +3 -3
- package/ClickOutside/index.js +4 -13
- package/ClickOutside/index.js.map +1 -1
- package/Collaps/index.cjs +5 -5
- package/Collaps/index.cjs.map +1 -1
- package/Collaps/index.d.ts +2 -2
- package/Collaps/index.js +5 -5
- package/Collaps/index.js.map +1 -1
- package/Container/index.d.ts +2 -2
- package/DataFilter/index.d.ts +2 -2
- package/DataFilter/options/DateFilter.cjs +3 -3
- package/DataFilter/options/DateFilter.cjs.map +1 -1
- package/DataFilter/options/DateFilter.js +3 -3
- package/DataFilter/options/DateFilter.js.map +1 -1
- package/DataFilter/options/DateRangeFilter.cjs +2 -2
- package/DataFilter/options/DateRangeFilter.cjs.map +1 -1
- package/DataFilter/options/DateRangeFilter.js +2 -2
- package/DataFilter/options/DateRangeFilter.js.map +1 -1
- package/DataFilter/options/MultiSelectFilter.cjs +3 -3
- package/DataFilter/options/MultiSelectFilter.cjs.map +1 -1
- package/DataFilter/options/MultiSelectFilter.js +3 -3
- package/DataFilter/options/MultiSelectFilter.js.map +1 -1
- package/DataFilter/options/NumberFilter.cjs +2 -2
- package/DataFilter/options/NumberFilter.cjs.map +1 -1
- package/DataFilter/options/NumberFilter.js +2 -2
- package/DataFilter/options/NumberFilter.js.map +1 -1
- package/DataFilter/options/NumberRangeFilter.cjs +2 -2
- package/DataFilter/options/NumberRangeFilter.cjs.map +1 -1
- package/DataFilter/options/NumberRangeFilter.js +2 -2
- package/DataFilter/options/NumberRangeFilter.js.map +1 -1
- package/DataFilter/options/SelectFilter.cjs +3 -3
- package/DataFilter/options/SelectFilter.cjs.map +1 -1
- package/DataFilter/options/SelectFilter.js +3 -3
- package/DataFilter/options/SelectFilter.js.map +1 -1
- package/DataFilter/options/TextFilter.cjs +2 -2
- package/DataFilter/options/TextFilter.cjs.map +1 -1
- package/DataFilter/options/TextFilter.js +2 -2
- package/DataFilter/options/TextFilter.js.map +1 -1
- package/Datatable/FilterBox.cjs +2 -2
- package/Datatable/FilterBox.cjs.map +1 -1
- package/Datatable/FilterBox.js +2 -2
- package/Datatable/FilterBox.js.map +1 -1
- package/Datatable/Row.cjs +2 -2
- package/Datatable/Row.cjs.map +1 -1
- package/Datatable/Row.js +2 -2
- package/Datatable/Row.js.map +1 -1
- package/Datatable/SelectedBox.cjs +2 -2
- package/Datatable/SelectedBox.cjs.map +1 -1
- package/Datatable/SelectedBox.js +2 -2
- package/Datatable/SelectedBox.js.map +1 -1
- package/Datatable/Table.cjs +1 -1
- package/Datatable/Table.cjs.map +1 -1
- package/Datatable/Table.js +1 -1
- package/Datatable/Table.js.map +1 -1
- package/Datatable/TableHead.cjs +3 -3
- package/Datatable/TableHead.cjs.map +1 -1
- package/Datatable/TableHead.js +3 -3
- package/Datatable/TableHead.js.map +1 -1
- package/Datatable/index.cjs +1 -1
- package/Datatable/index.cjs.map +1 -1
- package/Datatable/index.d.ts +2 -2
- package/Datatable/index.js +1 -1
- package/Datatable/index.js.map +1 -1
- package/Divider/index.cjs +3 -3
- package/Divider/index.cjs.map +1 -1
- package/Divider/index.d.ts +2 -2
- package/Divider/index.js +3 -3
- package/Divider/index.js.map +1 -1
- package/Drawer/index.cjs +2 -2
- package/Drawer/index.cjs.map +1 -1
- package/Drawer/index.js +2 -2
- package/Drawer/index.js.map +1 -1
- package/FilePicker/index.cjs +115 -0
- package/FilePicker/index.cjs.map +1 -0
- package/FilePicker/index.d.ts +23 -0
- package/FilePicker/index.js +113 -0
- package/FilePicker/index.js.map +1 -0
- package/Form/index.cjs +1 -1
- package/Form/index.cjs.map +1 -1
- package/Form/index.d.ts +2 -2
- package/Form/index.js +1 -1
- package/Form/index.js.map +1 -1
- package/GalleryPicker/index.cjs +88 -0
- package/GalleryPicker/index.cjs.map +1 -0
- package/GalleryPicker/index.d.ts +26 -0
- package/GalleryPicker/index.js +86 -0
- package/GalleryPicker/index.js.map +1 -0
- package/GridContainer/index.d.ts +2 -2
- package/GridItem/index.d.ts +2 -2
- package/IconButton/index.cjs +6 -3
- package/IconButton/index.cjs.map +1 -1
- package/IconButton/index.d.ts +2 -2
- package/IconButton/index.js +6 -3
- package/IconButton/index.js.map +1 -1
- package/Image/index.cjs +2 -14
- package/Image/index.cjs.map +1 -1
- package/Image/index.d.ts +3 -5
- package/Image/index.js +3 -15
- package/Image/index.js.map +1 -1
- package/Input/index.cjs +10 -10
- package/Input/index.cjs.map +1 -1
- package/Input/index.d.ts +14 -14
- package/Input/index.js +10 -10
- package/Input/index.js.map +1 -1
- package/InputNumber/index.d.ts +2 -2
- package/Label/index.cjs +1 -1
- package/Label/index.cjs.map +1 -1
- package/Label/index.d.ts +2 -2
- package/Label/index.js +1 -1
- package/Label/index.js.map +1 -1
- package/Layer/index.cjs +12 -13
- package/Layer/index.cjs.map +1 -1
- package/Layer/index.d.ts +5 -5
- package/Layer/index.js +13 -14
- package/Layer/index.js.map +1 -1
- package/LineProgress/index.cjs +6 -6
- package/LineProgress/index.cjs.map +1 -1
- package/LineProgress/index.d.ts +2 -2
- package/LineProgress/index.js +6 -6
- package/LineProgress/index.js.map +1 -1
- package/Link/index.cjs +41 -0
- package/Link/index.cjs.map +1 -0
- package/Link/index.d.ts +17 -0
- package/Link/index.js +39 -0
- package/Link/index.js.map +1 -0
- package/List/index.cjs +1 -1
- package/List/index.cjs.map +1 -1
- package/List/index.d.ts +2 -2
- package/List/index.js +1 -1
- package/List/index.js.map +1 -1
- package/ListItem/index.cjs +8 -8
- package/ListItem/index.cjs.map +1 -1
- package/ListItem/index.d.ts +2 -2
- package/ListItem/index.js +8 -8
- package/ListItem/index.js.map +1 -1
- package/LoadingBox/index.cjs +2 -2
- package/LoadingBox/index.cjs.map +1 -1
- package/LoadingBox/index.d.ts +2 -2
- package/LoadingBox/index.js +2 -2
- package/LoadingBox/index.js.map +1 -1
- package/Menu/index.cjs +25 -14
- package/Menu/index.cjs.map +1 -1
- package/Menu/index.d.ts +6 -4
- package/Menu/index.js +25 -14
- package/Menu/index.js.map +1 -1
- package/Modal/index.cjs +5 -5
- package/Modal/index.cjs.map +1 -1
- package/Modal/index.js +5 -5
- package/Modal/index.js.map +1 -1
- package/Option/index.d.ts +2 -2
- package/PasswordInput/index.cjs +21 -0
- package/PasswordInput/index.cjs.map +1 -0
- package/PasswordInput/index.d.ts +11 -0
- package/PasswordInput/index.js +19 -0
- package/PasswordInput/index.js.map +1 -0
- package/Portal/index.cjs +1 -1
- package/Portal/index.cjs.map +1 -1
- package/Portal/index.d.ts +3 -3
- package/Portal/index.js +1 -1
- package/Portal/index.js.map +1 -1
- package/Radio/index.d.ts +2 -2
- package/RangeSlider/index.cjs +158 -0
- package/RangeSlider/index.cjs.map +1 -0
- package/RangeSlider/index.d.ts +24 -0
- package/RangeSlider/index.js +156 -0
- package/RangeSlider/index.js.map +1 -0
- package/Scrollbar/index.cjs +6 -6
- package/Scrollbar/index.cjs.map +1 -1
- package/Scrollbar/index.d.ts +3 -3
- package/Scrollbar/index.js +6 -6
- package/Scrollbar/index.js.map +1 -1
- package/Select/index.cjs +2 -2
- package/Select/index.cjs.map +1 -1
- package/Select/index.d.ts +5 -5
- package/Select/index.js +2 -2
- package/Select/index.js.map +1 -1
- package/Skeleton/index.cjs +7 -5
- package/Skeleton/index.cjs.map +1 -1
- package/Skeleton/index.js +7 -5
- package/Skeleton/index.js.map +1 -1
- package/Stack/index.d.ts +2 -2
- package/Switch/index.cjs +2 -2
- package/Switch/index.cjs.map +1 -1
- package/Switch/index.d.ts +3 -3
- package/Switch/index.js +2 -2
- package/Switch/index.js.map +1 -1
- package/Tab/index.cjs +23 -2
- package/Tab/index.cjs.map +1 -1
- package/Tab/index.d.ts +2 -2
- package/Tab/index.js +25 -4
- package/Tab/index.js.map +1 -1
- package/Table/index.cjs +9 -9
- package/Table/index.cjs.map +1 -1
- package/Table/index.d.ts +2 -2
- package/Table/index.js +9 -9
- package/Table/index.js.map +1 -1
- package/TableBody/index.d.ts +2 -2
- package/TableCell/index.cjs +1 -1
- package/TableCell/index.cjs.map +1 -1
- package/TableCell/index.d.ts +2 -2
- package/TableCell/index.js +1 -1
- package/TableCell/index.js.map +1 -1
- package/TableFooter/index.d.ts +2 -2
- package/TableHead/index.d.ts +2 -2
- package/TablePagination/index.cjs +2 -2
- package/TablePagination/index.cjs.map +1 -1
- package/TablePagination/index.d.ts +2 -2
- package/TablePagination/index.js +2 -2
- package/TablePagination/index.js.map +1 -1
- package/TableRow/index.d.ts +2 -2
- package/Tabs/context.cjs +11 -0
- package/Tabs/context.cjs.map +1 -0
- package/Tabs/context.js +8 -0
- package/Tabs/context.js.map +1 -0
- package/Tabs/index.cjs +83 -168
- package/Tabs/index.cjs.map +1 -1
- package/Tabs/index.d.ts +4 -22
- package/Tabs/index.js +86 -171
- package/Tabs/index.js.map +1 -1
- package/Tabs/types.d.ts +16 -0
- package/Text/index.cjs +1 -1
- package/Text/index.cjs.map +1 -1
- package/Text/index.d.ts +2 -2
- package/Text/index.js +1 -1
- package/Text/index.js.map +1 -1
- package/Toast/index.cjs +15 -16
- package/Toast/index.cjs.map +1 -1
- package/Toast/index.js +16 -17
- package/Toast/index.js.map +1 -1
- package/Tooltip/index.cjs +2 -2
- package/Tooltip/index.cjs.map +1 -1
- package/Tooltip/index.js +2 -2
- package/Tooltip/index.js.map +1 -1
- package/ViewBox/index.d.ts +2 -2
- package/index.cjs +124 -110
- package/index.cjs.map +1 -1
- package/index.d.ts +8 -1
- package/index.js +8 -1
- package/index.js.map +1 -1
- package/package.json +3 -4
- package/readme.md +1 -1
- package/useBlurCss/index.cjs +1 -2
- package/useBlurCss/index.cjs.map +1 -1
- package/useBlurCss/index.js +1 -2
- package/useBlurCss/index.js.map +1 -1
- package/useContextMenu/index.cjs +2 -2
- package/useContextMenu/index.cjs.map +1 -1
- package/useContextMenu/index.d.ts +1 -1
- package/useContextMenu/index.js +2 -2
- package/useContextMenu/index.js.map +1 -1
- package/Paper/index.cjs +0 -16
- package/Paper/index.cjs.map +0 -1
- package/Paper/index.d.ts +0 -8
- package/Paper/index.js +0 -14
- package/Paper/index.js.map +0 -1
package/Calendar/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/Calendar/index.tsx"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef, useState } from 'react';\nimport Stack from '../Stack'\nimport IconButton from '../IconButton';\nimport IconKeyboardArrowRight from '@xanui/icons/KeyboardArrowRight';\nimport IconKeyboardArrowLeft from '@xanui/icons/KeyboardArrowLeft';\nimport Text from '../Text';\nimport Button from '../Button';\nimport ResetIcon from '@xanui/icons/Replay';\nimport ViewBox from '../ViewBox';\nimport { UseColorTemplateColor, useInterface, useBreakpointPropsType, useBreakpointProps } from '@xanui/core';\n\nexport type CalendarProps = {\n value?: Date | null;\n onChange?: (date: Date | null) => void;\n viewMode?: useBreakpointPropsType<\"year\" | \"month\" | \"day\">;\n onButtonClick?: (mode: CalendarProps[\"viewMode\"], value: CalendarProps[\"value\"]) => void;\n color?: useBreakpointPropsType<UseColorTemplateColor>;\n}\n\n\nconst ShowYears = ({ color, year, today, onClick }: any) => {\n let years: any[] = []\n const selectedRef: any = useRef(null)\n for (let y = 1900; y < today.getFullYear() + 40; y++) {\n const selected = year == y\n years.push(<Stack\n key={y}\n sx={{\n width: 50,\n p: .1\n }}\n className='calender-year-item'\n >\n <Button\n color={selected ? color : \"default\"}\n className='calender-year-button'\n size='small'\n corner=\"circle\"\n ref={selected ? selectedRef : null}\n onClick={() => onClick(y)}\n variant={selected ? \"fill\" : \"text\"}\n >\n {y}\n </Button>\n </Stack>)\n }\n\n useEffect(() => {\n if (selectedRef?.current) {\n selectedRef?.current.scrollIntoView({ behavior: \"smooth\", block: \"center\", inline: \"nearest\" })\n }\n }, [])\n\n return (\n <Stack\n sx={{\n flexWrap: \"wrap\",\n flexDirection: \"row\",\n overflow: \"hidden\",\n overflowY: \"auto\"\n }}\n className='calender-years'\n >\n {years}\n </Stack>\n )\n}\n\n\nconst Calendar = ({ value, ...rest }: CalendarProps) => {\n let [{ onChange, viewMode: VMode, onButtonClick, color }] = useInterface<any>(\"Calender\", rest, {})\n const _p: any = {}\n if (VMode) _p.VMode = VMode\n if (color) _p.color = color\n const p: any = useBreakpointProps(_p)\n color = p.color || \"brand\"\n\n let [viewMode, setViewMode] = useState<any>(p.VMode || \"day\");\n let [selectedDate, setSelectedDate] = useState(new Date());\n selectedDate = value instanceof Date ? value : selectedDate\n const [currentDate, setCurrentDate] = useState(selectedDate);\n const year = currentDate.getFullYear()\n const month = currentDate.getMonth()\n const daysInMonth = 32 - new Date(year, month, 32).getDate()\n const today = new Date();\n const btnWidth = 36\n const boxWidth = btnWidth * 7\n\n const showCalendar = () => {\n\n let firstDay = (new Date(year, month)).getDay();\n let rows = []\n let row = []\n\n const dayNames = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];\n for (let i = 0; i < dayNames.length; i++) {\n const k = dayNames[i];\n row.push(<Stack\n key={\"dayname-\" + i}\n sx={{\n width: btnWidth,\n height: btnWidth,\n alignItems: \"center\",\n justifyContent: \"center\"\n }}\n >\n <IconButton\n variant={\"text\"}\n color=\"default\"\n disabled\n >\n {k}\n </IconButton>\n </Stack>)\n }\n\n rows.push(<Stack flexRow key={\"header\"} className='calender-day-row'>\n {row}\n </Stack>);\n\n let date = 1;\n for (let i = 0; i < 6; i++) {\n let row = []\n for (let j = 0; j < 7; j++) {\n if (i === 0 && j < firstDay) {\n row.push(<Stack\n alignItems=\"center\"\n justifyContent=\"center\"\n key={date + j + i}\n sx={{\n width: btnWidth,\n height: btnWidth,\n alignItems: \"center\",\n justifyContent: \"center\"\n }}\n >\n\n </Stack>)\n } else if (date > daysInMonth) {\n break;\n } else {\n let isToday = date === today.getDate() && year === today.getFullYear() && month === today.getMonth()\n let isSelected = date === selectedDate.getDate() && year === selectedDate.getFullYear() && month === selectedDate.getMonth()\n\n let css: any = {}\n if (isToday) {\n css = {\n variant: \"fill\",\n color: \"default\"\n }\n }\n\n if (isSelected) {\n css = {\n variant: \"fill\",\n color: color\n }\n }\n\n row.push(<Stack\n sx={{\n width: btnWidth,\n height: btnWidth,\n alignItems: \"center\",\n justifyContent: \"center\"\n }}\n key={date + j + i}\n className='calender-day-item'\n >\n <IconButton\n className='calender-day-button'\n variant={isSelected ? \"fill\" : \"text\"}\n color={isToday ? color : \"default\"}\n {...css}\n data-value={date}\n onClick={(e: any) => {\n let d = e.target.getAttribute(\"data-value\")\n if (!d) return\n let selectedDate = new Date(year, month, parseInt(d))\n onChange ? onChange(selectedDate) : setSelectedDate(selectedDate)\n onButtonClick && onButtonClick(\"day\", selectedDate)\n }}\n >\n {date}\n </IconButton>\n </Stack>)\n date++;\n }\n }\n rows.push(<Stack flexRow key={\"row\" + i} className='calender-day-row'>\n {row}\n </Stack>);\n }\n return rows\n }\n\n const showMonth = () => {\n let months: any[] = []\n const monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];\n for (let m = 0; m < monthNames.length; m++) {\n const selected = currentDate.getMonth() === m\n\n months.push(<Stack\n key={m}\n width={\"50%\"}\n alignItems=\"center\"\n justifyContent=\"center\"\n p={.1}\n className='calender-months-item'\n >\n <Button\n color={selected ? color : \"default\"}\n className='calender-month-button'\n size='small'\n corner=\"circle\"\n variant={selected ? \"fill\" : 'text'}\n onClick={() => {\n const v = new Date(currentDate.getFullYear(), m)\n setCurrentDate(v)\n setViewMode(\"day\")\n onButtonClick && onButtonClick(\"month\", v)\n }}\n sx={{\n color: selected ? \"brand.text\" : \"text.primary\"\n }}\n >\n {monthNames[m]}\n </Button>\n </Stack>)\n }\n\n return (\n <Stack\n className='calender-months'\n sx={{\n flexWrap: \"wrap\",\n overflow: \"hidden\",\n overflowY: \"auto\",\n flexDirection: \"row\"\n }}\n >\n {months}\n </Stack>\n )\n }\n\n let view: any = null\n switch (viewMode) {\n case \"year\":\n view = <ShowYears\n color={color}\n today={today}\n year={year}\n boxWidth={boxWidth}\n onClick={(y: any) => {\n currentDate.setFullYear(y)\n setCurrentDate(currentDate)\n setViewMode(\"month\")\n onButtonClick && onButtonClick(\"year\", currentDate)\n }}\n />\n break;\n case \"month\":\n view = showMonth()\n break;\n default:\n view = (<>\n\n {showCalendar()}\n </>\n )\n break;\n }\n\n return (\n <ViewBox\n className='calender-root'\n maxHeight={308}\n width={250}\n radius={1}\n bgcolor=\"background.secondary\"\n startContent={\n <Stack className='calender-header' flexRow alignItems=\"center\" justifyContent=\"space-between\" p={1}>\n <Text\n fontWeight=\"bold\"\n cursor=\"pointer\"\n onClick={() => setViewMode(viewMode !== 'day' ? \"day\" : \"year\")}\n flex={1}\n >\n {currentDate.toLocaleDateString(undefined, { year: 'numeric', month: 'long' })}\n </Text>\n <IconButton\n color=\"default\"\n variant='text'\n size={28}\n onClick={() => {\n setCurrentDate(new Date())\n onChange ? onChange(new Date()) : setSelectedDate(new Date())\n }}\n >\n <ResetIcon fontSize={20} />\n </IconButton>\n <IconButton\n color=\"default\"\n variant='text'\n size={28}\n onClick={() => {\n setCurrentDate(new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, 1))\n }}\n >\n <IconKeyboardArrowLeft />\n </IconButton>\n <IconButton\n color=\"default\"\n variant='text'\n size={28}\n onClick={() => {\n setCurrentDate(new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 1))\n }}\n >\n <IconKeyboardArrowRight />\n </IconButton>\n </Stack>\n }\n >\n <Stack height=\"100%\" p={.5} className='calender-container'>\n {view}\n </Stack>\n </ViewBox>\n );\n};\n\nexport default Calendar;"],"names":[],"mappings":";;;;;;;;;;;;;;AAqBA;;AAEI;AACA;AACI;AACA;AAGQ;AACA;AACH;;;;;;;AAuBT;AAGY;AACA;AACA;AACA;AACH;AAMb;AAGA;AAAkB;;;AAGd;AAAW;AACX;AAAW;AACX;AACA;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAII;;;AAIA;AACA;AACI;AACA;AAGQ;AACA;AACA;AACA;;;AAaZ;;AAKA;;AAEI;;AAEQ;AAKQ;AACA;AACA;AACA;AACH;;AAIF;;;;;;;;AAQC;AACI;AACA;;;;AAKJ;AACI;AACA;;;AAIR;AAEQ;AACA;AACA;AACA;;;AAaI;;AACA;AACA;AACA;;AAMZ;;;AAGR;;AAIJ;AACJ;;;;AAKI;;AAGI;AAeY;;;AAGA;;;;;;AAeJ;AACA;AACA;AACA;;AAMhB;;;AAII;;AAOY;;;AAGA;AACJ;;AAGR;;;AAGA;AACI;;;;AA8BgB;AACA;AACJ;AASI;;AAUA;;AAa5B;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/Calendar/index.tsx"],"sourcesContent":["\"use client\";\nimport { useEffect, useRef, useState } from 'react';\nimport Stack from '../Stack'\nimport IconButton from '../IconButton';\nimport IconKeyboardArrowRight from '@xanui/icons/KeyboardArrowRight';\nimport IconKeyboardArrowLeft from '@xanui/icons/KeyboardArrowLeft';\nimport Text from '../Text';\nimport Button from '../Button';\nimport ResetIcon from '@xanui/icons/Replay';\nimport ViewBox from '../ViewBox';\nimport { UseColorTemplateColor, useInterface, useBreakpointPropsType, useBreakpointProps } from '@xanui/core';\n\nexport type CalendarProps = {\n value?: Date | null;\n onChange?: (date: Date | null) => void;\n viewMode?: useBreakpointPropsType<\"year\" | \"month\" | \"day\">;\n onButtonClick?: (mode: CalendarProps[\"viewMode\"], value: CalendarProps[\"value\"]) => void;\n color?: useBreakpointPropsType<UseColorTemplateColor>;\n}\n\n\nconst ShowYears = ({ color, year, today, onClick }: any) => {\n let years: any[] = []\n const selectedRef: any = useRef(null)\n for (let y = 1900; y < today.getFullYear() + 40; y++) {\n const selected = year == y\n years.push(<Stack\n key={y}\n sx={{\n width: 50,\n p: .1\n }}\n className='calender-year-item'\n >\n <Button\n color={selected ? color : 'surface'}\n className='calender-year-button'\n size='small'\n corner=\"circle\"\n ref={selected ? selectedRef : null}\n onClick={() => onClick(y)}\n variant={selected ? \"fill\" : \"text\"}\n >\n {y}\n </Button>\n </Stack>)\n }\n\n useEffect(() => {\n if (selectedRef?.current) {\n selectedRef?.current.scrollIntoView({ behavior: \"smooth\", block: \"center\", inline: \"nearest\" })\n }\n }, [])\n\n return (\n <Stack\n sx={{\n flexWrap: \"wrap\",\n flexDirection: \"row\",\n overflow: \"hidden\",\n overflowY: \"auto\"\n }}\n className='calender-years'\n >\n {years}\n </Stack>\n )\n}\n\n\nconst Calendar = ({ value, ...rest }: CalendarProps) => {\n let [{ onChange, viewMode: VMode, onButtonClick, color }] = useInterface<any>(\"Calender\", rest, {})\n const _p: any = {}\n if (VMode) _p.VMode = VMode\n if (color) _p.color = color\n const p: any = useBreakpointProps(_p)\n color = p.color || \"primary\"\n\n let [viewMode, setViewMode] = useState<any>(p.VMode || \"day\");\n let [selectedDate, setSelectedDate] = useState(new Date());\n selectedDate = value instanceof Date ? value : selectedDate\n const [currentDate, setCurrentDate] = useState(selectedDate);\n const year = currentDate.getFullYear()\n const month = currentDate.getMonth()\n const daysInMonth = 32 - new Date(year, month, 32).getDate()\n const today = new Date();\n const btnWidth = 36\n const boxWidth = btnWidth * 7\n\n const showCalendar = () => {\n\n let firstDay = (new Date(year, month)).getDay();\n let rows = []\n let row = []\n\n const dayNames = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];\n for (let i = 0; i < dayNames.length; i++) {\n const k = dayNames[i];\n row.push(<Stack\n key={\"dayname-\" + i}\n sx={{\n width: btnWidth,\n height: btnWidth,\n alignItems: \"center\",\n justifyContent: \"center\"\n }}\n >\n <IconButton\n variant={\"text\"}\n color=\"surface\"\n disabled\n >\n {k}\n </IconButton>\n </Stack>)\n }\n\n rows.push(<Stack flexRow key={\"header\"} className='calender-day-row'>\n {row}\n </Stack>);\n\n let date = 1;\n for (let i = 0; i < 6; i++) {\n let row = []\n for (let j = 0; j < 7; j++) {\n if (i === 0 && j < firstDay) {\n row.push(<Stack\n alignItems=\"center\"\n justifyContent=\"center\"\n key={date + j + i}\n sx={{\n width: btnWidth,\n height: btnWidth,\n alignItems: \"center\",\n justifyContent: \"center\"\n }}\n >\n\n </Stack>)\n } else if (date > daysInMonth) {\n break;\n } else {\n let isToday = date === today.getDate() && year === today.getFullYear() && month === today.getMonth()\n let isSelected = date === selectedDate.getDate() && year === selectedDate.getFullYear() && month === selectedDate.getMonth()\n\n let css: any = {}\n if (isToday) {\n css = {\n variant: \"fill\",\n color: \"surface\"\n }\n }\n\n if (isSelected) {\n css = {\n variant: \"fill\",\n color: color\n }\n }\n\n row.push(<Stack\n sx={{\n width: btnWidth,\n height: btnWidth,\n alignItems: \"center\",\n justifyContent: \"center\"\n }}\n key={date + j + i}\n className='calender-day-item'\n >\n <IconButton\n className='calender-day-button'\n variant={isSelected ? \"fill\" : \"text\"}\n color={isToday ? color : \"surface\"}\n {...css}\n data-value={date}\n onClick={(e: any) => {\n let d = e.target.getAttribute(\"data-value\")\n if (!d) return\n let selectedDate = new Date(year, month, parseInt(d))\n onChange ? onChange(selectedDate) : setSelectedDate(selectedDate)\n onButtonClick && onButtonClick(\"day\", selectedDate)\n }}\n >\n {date}\n </IconButton>\n </Stack>)\n date++;\n }\n }\n rows.push(<Stack flexRow key={\"row\" + i} className='calender-day-row'>\n {row}\n </Stack>);\n }\n return rows\n }\n\n const showMonth = () => {\n let months: any[] = []\n const monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];\n for (let m = 0; m < monthNames.length; m++) {\n const selected = currentDate.getMonth() === m\n\n months.push(<Stack\n key={m}\n width={\"50%\"}\n alignItems=\"center\"\n justifyContent=\"center\"\n p={.1}\n className='calender-months-item'\n >\n <Button\n color={selected ? color : 'surface'}\n className='calender-month-button'\n size='small'\n corner=\"circle\"\n variant={selected ? \"fill\" : 'text'}\n onClick={() => {\n const v = new Date(currentDate.getFullYear(), m)\n setCurrentDate(v)\n setViewMode(\"day\")\n onButtonClick && onButtonClick(\"month\", v)\n }}\n sx={{\n color: selected ? \"primary.contrast\" : \"surface.contrast\"\n }}\n >\n {monthNames[m]}\n </Button>\n </Stack>)\n }\n\n return (\n <Stack\n className='calender-months'\n sx={{\n flexWrap: \"wrap\",\n overflow: \"hidden\",\n overflowY: \"auto\",\n flexDirection: \"row\"\n }}\n >\n {months}\n </Stack>\n )\n }\n\n let view: any = null\n switch (viewMode) {\n case \"year\":\n view = <ShowYears\n color={color}\n today={today}\n year={year}\n boxWidth={boxWidth}\n onClick={(y: any) => {\n currentDate.setFullYear(y)\n setCurrentDate(currentDate)\n setViewMode(\"month\")\n onButtonClick && onButtonClick(\"year\", currentDate)\n }}\n />\n break;\n case \"month\":\n view = showMonth()\n break;\n default:\n view = (<>\n\n {showCalendar()}\n </>\n )\n break;\n }\n\n return (\n <ViewBox\n className='calender-root'\n maxHeight={308}\n width={250}\n radius={1}\n bgcolor=\"surface.lighter\"\n startContent={\n <Stack className='calender-header' flexRow alignItems=\"center\" justifyContent=\"space-between\" p={1}>\n <Text\n fontWeight=\"bold\"\n cursor=\"pointer\"\n onClick={() => setViewMode(viewMode !== 'day' ? \"day\" : \"year\")}\n flex={1}\n >\n {currentDate.toLocaleDateString(undefined, { year: 'numeric', month: 'long' })}\n </Text>\n <IconButton\n color=\"surface\"\n variant='text'\n size={28}\n onClick={() => {\n setCurrentDate(new Date())\n onChange ? onChange(new Date()) : setSelectedDate(new Date())\n }}\n >\n <ResetIcon fontSize={20} />\n </IconButton>\n <IconButton\n color=\"surface\"\n variant='text'\n size={28}\n onClick={() => {\n setCurrentDate(new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, 1))\n }}\n >\n <IconKeyboardArrowLeft />\n </IconButton>\n <IconButton\n color=\"surface\"\n variant='text'\n size={28}\n onClick={() => {\n setCurrentDate(new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 1))\n }}\n >\n <IconKeyboardArrowRight />\n </IconButton>\n </Stack>\n }\n >\n <Stack height=\"100%\" p={.5} className='calender-container'>\n {view}\n </Stack>\n </ViewBox>\n );\n};\n\nexport default Calendar;"],"names":[],"mappings":";;;;;;;;;;;;;;AAqBA;;AAEI;AACA;AACI;AACA;AAGQ;AACA;AACH;;;;;;;AAuBT;AAGY;AACA;AACA;AACA;AACH;AAMb;AAGA;AAAkB;;;AAGd;AAAW;AACX;AAAW;AACX;AACA;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAII;;;AAIA;AACA;AACI;AACA;AAGQ;AACA;AACA;AACA;;;AAaZ;;AAKA;;AAEI;;AAEQ;AAKQ;AACA;AACA;AACA;AACH;;AAIF;;;;;;;;AAQC;AACI;AACA;;;;AAKJ;AACI;AACA;;;AAIR;AAEQ;AACA;AACA;AACA;;;AAaI;;AACA;AACA;AACA;;AAMZ;;;AAGR;;AAIJ;AACJ;;;;AAKI;;AAGI;AAeY;;;AAGA;;;;;;AAeJ;AACA;AACA;AACA;;AAMhB;;;AAII;;AAOY;;;AAGA;AACJ;;AAGR;;;AAGA;AACI;;;;AA8BgB;AACA;AACJ;AASI;;AAUA;;AAa5B;;"}
|
package/CalendarInput/index.cjs
CHANGED
|
@@ -18,7 +18,7 @@ const CalenderInput = (props) => {
|
|
|
18
18
|
let [_a] = core.useInterface("CanlendarInput", props, {}), { value, onChange, getInputValue, slotProps, placeholder } = _a, inputProps = tslib.__rest(_a, ["value", "onChange", "getInputValue", "slotProps", "placeholder"]);
|
|
19
19
|
const [target, setTarget] = React.useState();
|
|
20
20
|
const inputRef = React.useRef(null);
|
|
21
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(index, Object.assign({ readOnly: true, startIcon: jsxRuntime.jsx(CalendarIcon, {}), placeholder: placeholder }, inputProps, { endIcon: jsxRuntime.jsx(jsxRuntime.Fragment, { children: value && jsxRuntime.jsx(index$1, { children: jsxRuntime.jsx(index$2, { color: "
|
|
21
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(index, Object.assign({ readOnly: true, startIcon: jsxRuntime.jsx(CalendarIcon, {}), placeholder: placeholder }, inputProps, { endIcon: jsxRuntime.jsx(jsxRuntime.Fragment, { children: value && jsxRuntime.jsx(index$1, { children: jsxRuntime.jsx(index$2, { color: "surface", size: 28, variant: "text", onClick: () => {
|
|
22
22
|
onChange && onChange(null);
|
|
23
23
|
}, children: jsxRuntime.jsx(ClearIcon, { fontSize: 20 }) }) }) }), cursor: "pointer", ref: inputRef, onFocus: () => setTarget(target ? null : inputRef === null || inputRef === void 0 ? void 0 : inputRef.current), value: getInputValue ? getInputValue(value) : (value ? value.toLocaleDateString("en-US") : "") })), jsxRuntime.jsx(index$3, Object.assign({ target: target, placement: "bottom-left", bgcolor: "transparent" }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.menu, { children: jsxRuntime.jsx(index$4, { onClickOutside: () => setTarget(null), children: jsxRuntime.jsx(index$5, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.calender, { value: value, onChange: (e) => {
|
|
24
24
|
setTarget(null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/CalendarInput/index.tsx"],"sourcesContent":["\"use client\";\nimport Input, { InputProps } from '../Input'\nimport Menu, { MenuProps } from '../Menu'\nimport { useRef, useState } from 'react'\nimport Calendar, { CalendarProps } from '../Calendar'\nimport Stack from '../Stack'\nimport ClickOutside from '../ClickOutside'\nimport CalendarIcon from '@xanui/icons/CalendarMonth';\nimport IconButton from '../IconButton'\nimport ClearIcon from '@xanui/icons/Clear';\nimport { useInterface } from '@xanui/core'\n\nexport type CalenderInpurProps = Omit<InputProps, \"value\" | \"onChange\" | \"slotProps\"> & {\n value?: CalendarProps[\"value\"];\n onChange?: CalendarProps[\"onChange\"];\n getInputValue?: (value?: Date | null) => string;\n slotProps?: {\n input?: InputProps['slotProps'];\n calender?: CalendarProps;\n menu?: MenuProps;\n }\n}\n\nconst CalenderInput = (props: CalenderInpurProps) => {\n let [{ value, onChange, getInputValue, slotProps, placeholder, ...inputProps }] = useInterface<any>(\"CanlendarInput\", props, {})\n const [target, setTarget] = useState<any>()\n const inputRef: any = useRef(null)\n\n return (\n <>\n <Input\n readOnly\n startIcon={<CalendarIcon />}\n placeholder={placeholder}\n {...inputProps}\n endIcon={<>\n {value && <Stack>\n <IconButton\n color=\"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/CalendarInput/index.tsx"],"sourcesContent":["\"use client\";\nimport Input, { InputProps } from '../Input'\nimport Menu, { MenuProps } from '../Menu'\nimport { useRef, useState } from 'react'\nimport Calendar, { CalendarProps } from '../Calendar'\nimport Stack from '../Stack'\nimport ClickOutside from '../ClickOutside'\nimport CalendarIcon from '@xanui/icons/CalendarMonth';\nimport IconButton from '../IconButton'\nimport ClearIcon from '@xanui/icons/Clear';\nimport { useInterface } from '@xanui/core'\n\nexport type CalenderInpurProps = Omit<InputProps, \"value\" | \"onChange\" | \"slotProps\"> & {\n value?: CalendarProps[\"value\"];\n onChange?: CalendarProps[\"onChange\"];\n getInputValue?: (value?: Date | null) => string;\n slotProps?: {\n input?: InputProps['slotProps'];\n calender?: CalendarProps;\n menu?: MenuProps;\n }\n}\n\nconst CalenderInput = (props: CalenderInpurProps) => {\n let [{ value, onChange, getInputValue, slotProps, placeholder, ...inputProps }] = useInterface<any>(\"CanlendarInput\", props, {})\n const [target, setTarget] = useState<any>()\n const inputRef: any = useRef(null)\n\n return (\n <>\n <Input\n readOnly\n startIcon={<CalendarIcon />}\n placeholder={placeholder}\n {...inputProps}\n endIcon={<>\n {value && <Stack>\n <IconButton\n color=\"surface\"\n size={28}\n variant=\"text\"\n onClick={() => {\n onChange && onChange(null)\n }}\n >\n <ClearIcon fontSize={20} />\n </IconButton>\n </Stack>}\n </>}\n cursor=\"pointer\"\n ref={inputRef}\n onFocus={() => setTarget(target ? null : inputRef?.current)}\n value={getInputValue ? getInputValue(value) : (value ? value.toLocaleDateString(\"en-US\") : \"\")}\n />\n <Menu\n target={target}\n placement=\"bottom-left\"\n bgcolor=\"transparent\"\n {...slotProps?.menu}\n >\n <ClickOutside onClickOutside={() => setTarget(null)}>\n <Calendar\n {...slotProps?.calender}\n value={value}\n onChange={(e) => {\n setTarget(null)\n onChange && onChange(e)\n }}\n />\n </ClickOutside>\n </Menu>\n </>\n )\n}\n\nexport default CalenderInput"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAuBA;;;AAGI;;AAgB4B;AACJ;;AAuBA;AACJ;AAMxB;;"}
|
package/CalendarInput/index.js
CHANGED
|
@@ -16,7 +16,7 @@ const CalenderInput = (props) => {
|
|
|
16
16
|
let [_a] = useInterface("CanlendarInput", props, {}), { value, onChange, getInputValue, slotProps, placeholder } = _a, inputProps = __rest(_a, ["value", "onChange", "getInputValue", "slotProps", "placeholder"]);
|
|
17
17
|
const [target, setTarget] = useState();
|
|
18
18
|
const inputRef = useRef(null);
|
|
19
|
-
return (jsxs(Fragment, { children: [jsx(Input, Object.assign({ readOnly: true, startIcon: jsx(CalendarIcon, {}), placeholder: placeholder }, inputProps, { endIcon: jsx(Fragment, { children: value && jsx(Stack, { children: jsx(IconButton, { color: "
|
|
19
|
+
return (jsxs(Fragment, { children: [jsx(Input, Object.assign({ readOnly: true, startIcon: jsx(CalendarIcon, {}), placeholder: placeholder }, inputProps, { endIcon: jsx(Fragment, { children: value && jsx(Stack, { children: jsx(IconButton, { color: "surface", size: 28, variant: "text", onClick: () => {
|
|
20
20
|
onChange && onChange(null);
|
|
21
21
|
}, children: jsx(ClearIcon, { fontSize: 20 }) }) }) }), cursor: "pointer", ref: inputRef, onFocus: () => setTarget(target ? null : inputRef === null || inputRef === void 0 ? void 0 : inputRef.current), value: getInputValue ? getInputValue(value) : (value ? value.toLocaleDateString("en-US") : "") })), jsx(Menu, Object.assign({ target: target, placement: "bottom-left", bgcolor: "transparent" }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.menu, { children: jsx(ClickOutside, { onClickOutside: () => setTarget(null), children: jsx(Calendar, Object.assign({}, slotProps === null || slotProps === void 0 ? void 0 : slotProps.calender, { value: value, onChange: (e) => {
|
|
22
22
|
setTarget(null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/CalendarInput/index.tsx"],"sourcesContent":["\"use client\";\nimport Input, { InputProps } from '../Input'\nimport Menu, { MenuProps } from '../Menu'\nimport { useRef, useState } from 'react'\nimport Calendar, { CalendarProps } from '../Calendar'\nimport Stack from '../Stack'\nimport ClickOutside from '../ClickOutside'\nimport CalendarIcon from '@xanui/icons/CalendarMonth';\nimport IconButton from '../IconButton'\nimport ClearIcon from '@xanui/icons/Clear';\nimport { useInterface } from '@xanui/core'\n\nexport type CalenderInpurProps = Omit<InputProps, \"value\" | \"onChange\" | \"slotProps\"> & {\n value?: CalendarProps[\"value\"];\n onChange?: CalendarProps[\"onChange\"];\n getInputValue?: (value?: Date | null) => string;\n slotProps?: {\n input?: InputProps['slotProps'];\n calender?: CalendarProps;\n menu?: MenuProps;\n }\n}\n\nconst CalenderInput = (props: CalenderInpurProps) => {\n let [{ value, onChange, getInputValue, slotProps, placeholder, ...inputProps }] = useInterface<any>(\"CanlendarInput\", props, {})\n const [target, setTarget] = useState<any>()\n const inputRef: any = useRef(null)\n\n return (\n <>\n <Input\n readOnly\n startIcon={<CalendarIcon />}\n placeholder={placeholder}\n {...inputProps}\n endIcon={<>\n {value && <Stack>\n <IconButton\n color=\"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/CalendarInput/index.tsx"],"sourcesContent":["\"use client\";\nimport Input, { InputProps } from '../Input'\nimport Menu, { MenuProps } from '../Menu'\nimport { useRef, useState } from 'react'\nimport Calendar, { CalendarProps } from '../Calendar'\nimport Stack from '../Stack'\nimport ClickOutside from '../ClickOutside'\nimport CalendarIcon from '@xanui/icons/CalendarMonth';\nimport IconButton from '../IconButton'\nimport ClearIcon from '@xanui/icons/Clear';\nimport { useInterface } from '@xanui/core'\n\nexport type CalenderInpurProps = Omit<InputProps, \"value\" | \"onChange\" | \"slotProps\"> & {\n value?: CalendarProps[\"value\"];\n onChange?: CalendarProps[\"onChange\"];\n getInputValue?: (value?: Date | null) => string;\n slotProps?: {\n input?: InputProps['slotProps'];\n calender?: CalendarProps;\n menu?: MenuProps;\n }\n}\n\nconst CalenderInput = (props: CalenderInpurProps) => {\n let [{ value, onChange, getInputValue, slotProps, placeholder, ...inputProps }] = useInterface<any>(\"CanlendarInput\", props, {})\n const [target, setTarget] = useState<any>()\n const inputRef: any = useRef(null)\n\n return (\n <>\n <Input\n readOnly\n startIcon={<CalendarIcon />}\n placeholder={placeholder}\n {...inputProps}\n endIcon={<>\n {value && <Stack>\n <IconButton\n color=\"surface\"\n size={28}\n variant=\"text\"\n onClick={() => {\n onChange && onChange(null)\n }}\n >\n <ClearIcon fontSize={20} />\n </IconButton>\n </Stack>}\n </>}\n cursor=\"pointer\"\n ref={inputRef}\n onFocus={() => setTarget(target ? null : inputRef?.current)}\n value={getInputValue ? getInputValue(value) : (value ? value.toLocaleDateString(\"en-US\") : \"\")}\n />\n <Menu\n target={target}\n placement=\"bottom-left\"\n bgcolor=\"transparent\"\n {...slotProps?.menu}\n >\n <ClickOutside onClickOutside={() => setTarget(null)}>\n <Calendar\n {...slotProps?.calender}\n value={value}\n onChange={(e) => {\n setTarget(null)\n onChange && onChange(e)\n }}\n />\n </ClickOutside>\n </Menu>\n </>\n )\n}\n\nexport default CalenderInput"],"names":[],"mappings":";;;;;;;;;;;;;;AAuBA;;;AAGI;;AAgB4B;AACJ;;AAuBA;AACJ;AAMxB;;"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var tslib = require('tslib');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var core = require('@xanui/core');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
|
|
9
|
+
const Carousel = React.forwardRef((_a, ref) => {
|
|
10
|
+
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
11
|
+
var { children } = _a, rest = tslib.__rest(_a, ["children"]);
|
|
12
|
+
const [index, setIndex] = React.useState(0);
|
|
13
|
+
const childs = React.Children.toArray(children);
|
|
14
|
+
const total = childs.length;
|
|
15
|
+
const track = React.useRef(null);
|
|
16
|
+
const animating = React.useRef(() => { });
|
|
17
|
+
const state = React.useRef({ x: 0 });
|
|
18
|
+
const autoplayRef = React.useRef(null);
|
|
19
|
+
let [_k] = core.useInterface("Carousel", rest, {}), { slidesToShow, slidesToScroll, loop, autoplay, autoplayInterval, duration, transition, easing, onChange, onBeforeChange, onNext, onBeforeNext, onPrev, onBeforePrev } = _k, props = tslib.__rest(_k, ["slidesToShow", "slidesToScroll", "loop", "autoplay", "autoplayInterval", "duration", "transition", "easing", "onChange", "onBeforeChange", "onNext", "onBeforeNext", "onPrev", "onBeforePrev"]);
|
|
20
|
+
const _p = {};
|
|
21
|
+
if (slidesToShow)
|
|
22
|
+
_p.slidesToShow = slidesToShow;
|
|
23
|
+
if (slidesToScroll)
|
|
24
|
+
_p.slidesToScroll = slidesToScroll;
|
|
25
|
+
if (loop)
|
|
26
|
+
_p.loop = loop;
|
|
27
|
+
if (autoplay)
|
|
28
|
+
_p.autoplay = autoplay;
|
|
29
|
+
if (autoplayInterval)
|
|
30
|
+
_p.autoplayInterval = autoplayInterval;
|
|
31
|
+
if (duration)
|
|
32
|
+
_p.duration = duration;
|
|
33
|
+
if (transition)
|
|
34
|
+
_p.transition = transition;
|
|
35
|
+
if (easing)
|
|
36
|
+
_p.easing = easing;
|
|
37
|
+
const p = core.useBreakpointProps(_p);
|
|
38
|
+
slidesToShow = (_b = p.slidesToShow) !== null && _b !== void 0 ? _b : 1;
|
|
39
|
+
slidesToScroll = (_c = p.slidesToScroll) !== null && _c !== void 0 ? _c : 1;
|
|
40
|
+
autoplay = (_d = p.autoplay) !== null && _d !== void 0 ? _d : false;
|
|
41
|
+
autoplayInterval = (_e = p.autoplayInterval) !== null && _e !== void 0 ? _e : 3000;
|
|
42
|
+
loop = (_f = p.loop) !== null && _f !== void 0 ? _f : (autoplay ? true : false);
|
|
43
|
+
duration = (_g = p.duration) !== null && _g !== void 0 ? _g : 500;
|
|
44
|
+
transition = (_h = p.transition) !== null && _h !== void 0 ? _h : undefined;
|
|
45
|
+
easing = (_j = p.easing) !== null && _j !== void 0 ? _j : undefined;
|
|
46
|
+
if (slidesToShow > total) {
|
|
47
|
+
slidesToShow = total;
|
|
48
|
+
}
|
|
49
|
+
if (slidesToScroll > total) {
|
|
50
|
+
slidesToScroll = total;
|
|
51
|
+
}
|
|
52
|
+
if (slidesToShow <= 0) {
|
|
53
|
+
slidesToShow = 1;
|
|
54
|
+
}
|
|
55
|
+
if (slidesToScroll <= 0) {
|
|
56
|
+
slidesToScroll = 1;
|
|
57
|
+
}
|
|
58
|
+
if (slidesToScroll > slidesToShow) {
|
|
59
|
+
slidesToScroll = slidesToShow;
|
|
60
|
+
}
|
|
61
|
+
const goTo = (_index) => {
|
|
62
|
+
if (_index === index)
|
|
63
|
+
return;
|
|
64
|
+
if (_index < 0 || _index > total - slidesToShow)
|
|
65
|
+
return;
|
|
66
|
+
setIndex(_index);
|
|
67
|
+
const indexes = [];
|
|
68
|
+
for (let i = 0; i < slidesToShow; i++) {
|
|
69
|
+
indexes.push(_index + i);
|
|
70
|
+
}
|
|
71
|
+
onChange && onChange(_index, indexes);
|
|
72
|
+
const itemWidth = 100 / slidesToShow;
|
|
73
|
+
const trackEle = track.current;
|
|
74
|
+
const translate = itemWidth * _index;
|
|
75
|
+
animating.current();
|
|
76
|
+
animating.current = core.animate({
|
|
77
|
+
duration: duration,
|
|
78
|
+
from: { x: state.current.x },
|
|
79
|
+
to: { x: translate },
|
|
80
|
+
onUpdate: ({ x }) => {
|
|
81
|
+
state.current.x = x;
|
|
82
|
+
trackEle.style.transform = `translateX(-${x}%)`;
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
const next = () => {
|
|
87
|
+
let _index = index;
|
|
88
|
+
if (loop) {
|
|
89
|
+
if (_index >= total - slidesToShow) {
|
|
90
|
+
_index = 0;
|
|
91
|
+
}
|
|
92
|
+
else if (index + slidesToScroll > total - slidesToShow) {
|
|
93
|
+
_index = total - slidesToShow;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
_index = index + slidesToScroll;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
if (_index >= total - slidesToShow) {
|
|
101
|
+
_index = total - slidesToShow;
|
|
102
|
+
}
|
|
103
|
+
else if (index + slidesToScroll > total - slidesToShow) {
|
|
104
|
+
_index = total - slidesToShow;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
_index = index + slidesToScroll;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const indexes = [];
|
|
111
|
+
for (let i = 0; i < slidesToShow; i++) {
|
|
112
|
+
indexes.push(_index + i);
|
|
113
|
+
}
|
|
114
|
+
onNext && onNext(_index, indexes);
|
|
115
|
+
goTo(_index);
|
|
116
|
+
};
|
|
117
|
+
const prev = () => {
|
|
118
|
+
let _index = index;
|
|
119
|
+
if (loop) {
|
|
120
|
+
if (_index <= 0) {
|
|
121
|
+
_index = total - slidesToShow;
|
|
122
|
+
}
|
|
123
|
+
else if (index - slidesToScroll < 0) {
|
|
124
|
+
_index = 0;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
_index = index - slidesToScroll;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
if (_index <= 0) {
|
|
132
|
+
_index = 0;
|
|
133
|
+
}
|
|
134
|
+
else if (index - slidesToScroll < 0) {
|
|
135
|
+
_index = 0;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
_index = index - slidesToScroll;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const indexes = [];
|
|
142
|
+
for (let i = 0; i < slidesToShow; i++) {
|
|
143
|
+
indexes.push(_index + i);
|
|
144
|
+
}
|
|
145
|
+
onPrev && onPrev(_index, indexes);
|
|
146
|
+
goTo(_index);
|
|
147
|
+
};
|
|
148
|
+
const stopAutoplay = () => {
|
|
149
|
+
if (autoplayRef.current) {
|
|
150
|
+
clearTimeout(autoplayRef.current);
|
|
151
|
+
autoplayRef.current = null;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const startAutoplay = () => {
|
|
155
|
+
stopAutoplay();
|
|
156
|
+
autoplayRef.current = setTimeout(next, autoplayInterval);
|
|
157
|
+
};
|
|
158
|
+
React.useEffect(() => {
|
|
159
|
+
if (!autoplay)
|
|
160
|
+
return;
|
|
161
|
+
startAutoplay();
|
|
162
|
+
return () => stopAutoplay();
|
|
163
|
+
}, [index, autoplay]);
|
|
164
|
+
const indexes = React.useMemo(() => {
|
|
165
|
+
const idx = [];
|
|
166
|
+
for (let i = 0; i < slidesToShow; i++) {
|
|
167
|
+
idx.push(index + i);
|
|
168
|
+
}
|
|
169
|
+
return idx;
|
|
170
|
+
}, [index, slidesToShow]);
|
|
171
|
+
React.useImperativeHandle(ref, () => ({
|
|
172
|
+
next,
|
|
173
|
+
prev,
|
|
174
|
+
goTo,
|
|
175
|
+
getIndex: () => index,
|
|
176
|
+
}));
|
|
177
|
+
React.useLayoutEffect(() => {
|
|
178
|
+
goTo(0);
|
|
179
|
+
}, []);
|
|
180
|
+
const startX = React.useRef(0);
|
|
181
|
+
const isDragging = React.useRef(false);
|
|
182
|
+
const handleStart = (x) => {
|
|
183
|
+
startX.current = x;
|
|
184
|
+
isDragging.current = true;
|
|
185
|
+
};
|
|
186
|
+
const handleEnd = (x) => {
|
|
187
|
+
if (!isDragging.current)
|
|
188
|
+
return;
|
|
189
|
+
const diff = x - startX.current;
|
|
190
|
+
if (diff > 50)
|
|
191
|
+
prev();
|
|
192
|
+
else if (diff < -50)
|
|
193
|
+
next();
|
|
194
|
+
isDragging.current = false;
|
|
195
|
+
};
|
|
196
|
+
return (jsxRuntime.jsx(core.Tag, Object.assign({}, props, { baseClass: 'carousel', ref: ref, sxr: {
|
|
197
|
+
width: "100%",
|
|
198
|
+
overflow: "hidden",
|
|
199
|
+
cursor: "grab",
|
|
200
|
+
touchAction: "pan-y",
|
|
201
|
+
position: "relative",
|
|
202
|
+
}, children: jsxRuntime.jsx(core.Tag, { baseClass: 'carousel-track', ref: track, sxr: {
|
|
203
|
+
display: "flex",
|
|
204
|
+
willChange: "transform",
|
|
205
|
+
flexDirection: "row",
|
|
206
|
+
}, onPointerDown: (e) => {
|
|
207
|
+
e.preventDefault();
|
|
208
|
+
handleStart(e.clientX);
|
|
209
|
+
}, onPointerUp: (e) => handleEnd(e.clientX), onTouchStart: (e) => {
|
|
210
|
+
e.preventDefault();
|
|
211
|
+
handleStart(e.touches[0].clientX);
|
|
212
|
+
}, onTouchEnd: (e) => handleEnd(e.changedTouches[0].clientX), onMouseEnter: () => {
|
|
213
|
+
stopAutoplay();
|
|
214
|
+
}, onMouseLeave: () => {
|
|
215
|
+
if (autoplay)
|
|
216
|
+
startAutoplay();
|
|
217
|
+
}, children: childs.map((child, index) => (transition ? jsxRuntime.jsx(core.Transition, { open: indexes.includes(index), variant: transition, easing: easing, duration: duration, initialTransition: false, children: jsxRuntime.jsx(core.Tag, { baseClass: 'carousel-item', sxr: {
|
|
218
|
+
p: 1,
|
|
219
|
+
userSelect: "none",
|
|
220
|
+
flexShrink: 0,
|
|
221
|
+
width: `${100 / slidesToShow}%`,
|
|
222
|
+
}, children: child }, `${index}`) }, index) : jsxRuntime.jsx(core.Tag, { baseClass: 'carousel-item', sxr: {
|
|
223
|
+
p: 1,
|
|
224
|
+
userSelect: "none",
|
|
225
|
+
flexShrink: 0,
|
|
226
|
+
width: `${100 / slidesToShow}%`,
|
|
227
|
+
}, children: child }, `${index}`))) }) })));
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
module.exports = Carousel;
|
|
231
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/Carousel/index.tsx"],"sourcesContent":["\"use client\"\nimport { animate, Transition, TransitionProps } from '@xanui/core';\nimport { Children, forwardRef, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from 'react'\nimport { Tag, TagProps, TagComponentType, useInterface, useBreakpointProps, useBreakpointPropsType } from '@xanui/core';\n\nexport type CarouselRef = {\n next: () => void;\n prev: () => void;\n goTo: (index: number) => void;\n getIndex: () => number;\n};\n\nexport type CarouselProps<T extends TagComponentType = \"div\"> = Omit<TagProps<T>, \"children\" | \"onChange\" | \"transition\"> & {\n children: React.ReactNode\n slidesToShow?: useBreakpointPropsType<number>;\n slidesToScroll?: useBreakpointPropsType<number>;\n infinite?: useBreakpointPropsType<boolean>;\n autoplay?: useBreakpointPropsType<boolean>;\n autoplayInterval?: useBreakpointPropsType<number>;\n loop?: useBreakpointPropsType<boolean>;\n duration?: useBreakpointPropsType<number>;\n transition?: useBreakpointPropsType<TransitionProps[\"variant\"]>;\n easing?: useBreakpointPropsType<TransitionProps[\"easing\"]>;\n\n onChange?: (index: number, indexes: number[]) => void;\n onNext?: (index: number, indexes: number[]) => void;\n onPrev?: (index: number, indexes: number[]) => void;\n}\n\nconst Carousel = forwardRef(<T extends TagComponentType = \"div\">({ children, ...rest }: CarouselProps<T>, ref: React.Ref<CarouselRef>) => {\n const [index, setIndex] = useState(0)\n const childs = Children.toArray(children)\n const total = childs.length\n const track = useRef<HTMLElement>(null)\n const animating = useRef(() => { })\n const state = useRef({ x: 0 })\n const autoplayRef = useRef<any | null>(null)\n\n let [{\n slidesToShow,\n slidesToScroll,\n loop,\n autoplay,\n autoplayInterval,\n duration,\n transition,\n easing,\n\n onChange,\n onBeforeChange,\n onNext,\n onBeforeNext,\n onPrev,\n onBeforePrev,\n\n ...props\n }] = useInterface<any>(\"Carousel\", rest, {})\n\n const _p: any = {}\n if (slidesToShow) _p.slidesToShow = slidesToShow\n if (slidesToScroll) _p.slidesToScroll = slidesToScroll\n if (loop) _p.loop = loop\n if (autoplay) _p.autoplay = autoplay\n if (autoplayInterval) _p.autoplayInterval = autoplayInterval\n if (duration) _p.duration = duration\n if (transition) _p.transition = transition\n if (easing) _p.easing = easing\n\n\n const p: any = useBreakpointProps(_p)\n\n slidesToShow = p.slidesToShow ?? 1\n slidesToScroll = p.slidesToScroll ?? 1\n autoplay = p.autoplay ?? false\n autoplayInterval = p.autoplayInterval ?? 3000\n loop = p.loop ?? (autoplay ? true : false)\n duration = p.duration ?? 500\n transition = p.transition ?? undefined\n easing = p.easing ?? undefined\n\n if (slidesToShow > total) {\n slidesToShow = total\n }\n if (slidesToScroll > total) {\n slidesToScroll = total\n }\n if (slidesToShow <= 0) {\n slidesToShow = 1\n }\n if (slidesToScroll <= 0) {\n slidesToScroll = 1\n }\n if (slidesToScroll > slidesToShow) {\n slidesToScroll = slidesToShow\n }\n\n const goTo = (_index: number) => {\n if (_index === index) return;\n if (_index < 0 || _index > total - slidesToShow) return;\n\n setIndex(_index);\n\n const indexes = []\n for (let i = 0; i < slidesToShow; i++) {\n indexes.push(_index + i)\n }\n onChange && onChange(_index, indexes)\n\n const itemWidth = 100 / slidesToShow\n const trackEle = track.current!;\n const translate = itemWidth * _index\n animating.current();\n animating.current = animate({\n duration: duration,\n from: { x: state.current.x },\n to: { x: translate },\n onUpdate: ({ x }) => {\n state.current.x = x\n trackEle.style.transform = `translateX(-${x}%)`\n },\n });\n }\n\n const next = () => {\n let _index = index\n if (loop) {\n if (_index >= total - slidesToShow) {\n _index = 0\n } else if (index + slidesToScroll > total - slidesToShow) {\n _index = total - slidesToShow\n } else {\n _index = index + slidesToScroll\n }\n } else {\n if (_index >= total - slidesToShow) {\n _index = total - slidesToShow\n } else if (index + slidesToScroll > total - slidesToShow) {\n _index = total - slidesToShow\n } else {\n _index = index + slidesToScroll\n }\n }\n const indexes = []\n for (let i = 0; i < slidesToShow; i++) {\n indexes.push(_index + i)\n }\n onNext && onNext(_index, indexes)\n goTo(_index)\n }\n\n const prev = () => {\n let _index = index\n if (loop) {\n if (_index <= 0) {\n _index = total - slidesToShow\n } else if (index - slidesToScroll < 0) {\n _index = 0\n } else {\n _index = index - slidesToScroll\n }\n } else {\n if (_index <= 0) {\n _index = 0\n } else if (index - slidesToScroll < 0) {\n _index = 0\n } else {\n _index = index - slidesToScroll\n }\n }\n\n const indexes = []\n for (let i = 0; i < slidesToShow; i++) {\n indexes.push(_index + i)\n }\n onPrev && onPrev(_index, indexes)\n goTo(_index)\n }\n\n const stopAutoplay = () => {\n if (autoplayRef.current) {\n clearTimeout(autoplayRef.current);\n autoplayRef.current = null;\n }\n }\n\n const startAutoplay = () => {\n stopAutoplay();\n autoplayRef.current = setTimeout(next, autoplayInterval);\n }\n\n useEffect(() => {\n if (!autoplay) return;\n startAutoplay();\n return () => stopAutoplay();\n }, [index, autoplay]);\n\n const indexes = useMemo(() => {\n const idx = []\n for (let i = 0; i < slidesToShow; i++) {\n idx.push(index + i)\n }\n return idx\n }, [index, slidesToShow])\n\n useImperativeHandle(ref, () => ({\n next,\n prev,\n goTo,\n getIndex: () => index,\n }));\n\n useLayoutEffect(() => {\n goTo(0)\n }, [])\n\n const startX = useRef(0);\n const isDragging = useRef(false);\n\n const handleStart = (x: number) => {\n startX.current = x;\n isDragging.current = true;\n };\n\n const handleEnd = (x: number) => {\n if (!isDragging.current) return;\n const diff = x - startX.current;\n if (diff > 50) prev();\n else if (diff < -50) next();\n isDragging.current = false;\n };\n\n return (\n <Tag\n {...props}\n baseClass='carousel'\n ref={ref}\n sxr={{\n width: \"100%\",\n overflow: \"hidden\",\n cursor: \"grab\",\n touchAction: \"pan-y\",\n position: \"relative\",\n }}\n >\n <Tag\n baseClass='carousel-track'\n ref={track}\n sxr={{\n display: \"flex\",\n willChange: \"transform\",\n flexDirection: \"row\",\n }}\n onPointerDown={(e: any) => {\n e.preventDefault()\n handleStart(e.clientX)\n }}\n onPointerUp={(e: any) => handleEnd(e.clientX)}\n onTouchStart={(e: any) => {\n e.preventDefault()\n handleStart(e.touches[0].clientX)\n }}\n onTouchEnd={(e: any) => handleEnd(e.changedTouches[0].clientX)}\n\n onMouseEnter={() => {\n stopAutoplay()\n }}\n onMouseLeave={() => {\n if (autoplay) startAutoplay()\n }}\n >\n {\n childs.map((child, index) => (\n transition ? <Transition\n key={index}\n open={indexes.includes(index)}\n variant={transition}\n easing={easing}\n duration={duration}\n initialTransition={false}\n >\n <Tag\n key={`${index}`}\n baseClass='carousel-item'\n sxr={{\n p: 1,\n userSelect: \"none\",\n flexShrink: 0,\n width: `${100 / slidesToShow}%`,\n }}\n >\n {child}\n </Tag>\n </Transition> : <Tag\n key={`${index}`}\n baseClass='carousel-item'\n sxr={{\n p: 1,\n userSelect: \"none\",\n flexShrink: 0,\n width: `${100 / slidesToShow}%`,\n }}\n >\n {child}\n </Tag>\n ))\n }\n </Tag>\n </Tag>\n )\n})\n\nexport default Carousel"],"names":[],"mappings":";;;;;;;;AA6BA;;AAAiE;;;AAG7D;AACA;;;AAGA;;;AAuBA;AAAkB;AAClB;AAAoB;AACpB;AAAU;AACV;AAAc;AACd;AAAsB;AACtB;AAAc;AACd;AAAgB;AAChB;AAAY;AAGZ;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;;;AAGA;;;AAGA;;;AAGA;;;AAGA;;;AAIA;;;;;;;AAOI;AACI;;AAEJ;AAEA;AACA;AACA;;AAEA;AACI;;AAEA;AACA;AACI;;;AAGP;AACL;;;;AAKQ;;;;AAGI;;;AAEA;;;;AAGJ;AACI;;;AAEA;;;AAEA;;;;AAIR;AACI;;AAEJ;;AAEJ;;;;AAKQ;AACI;;AACG;;;;AAGH;;;;AAGJ;;;AAEO;;;;AAGH;;;;AAKR;AACI;;AAEJ;;AAEJ;;AAGI;AACI;AACA;;AAER;;AAGI;;AAEJ;;AAGI;;AACA;AACA;AACJ;AAEA;;AAEI;AACI;;AAEJ;AACJ;AAEA;;;;AAII;AACH;;;;AAMD;AACA;AAEA;AACI;AACA;AACJ;AAEA;;;AAEI;;AACe;;AACM;AACrB;AACJ;AAEA;AAMY;AACA;AACA;AACA;AACA;AACH;AAMO;AACA;AACA;AACH;;AAGG;;;;;AAUA;AACJ;AAEI;AAAc;;AAiBE;AACA;AACA;AACA;;AASJ;AACA;AACA;AACA;;AAUhC;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as React$1 from 'react';
|
|
2
|
+
import { TagComponentType, TagProps, useBreakpointPropsType, TransitionProps } from '@xanui/core';
|
|
3
|
+
|
|
4
|
+
type CarouselRef = {
|
|
5
|
+
next: () => void;
|
|
6
|
+
prev: () => void;
|
|
7
|
+
goTo: (index: number) => void;
|
|
8
|
+
getIndex: () => number;
|
|
9
|
+
};
|
|
10
|
+
type CarouselProps<T extends TagComponentType = "div"> = Omit<TagProps<T>, "children" | "onChange" | "transition"> & {
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
slidesToShow?: useBreakpointPropsType<number>;
|
|
13
|
+
slidesToScroll?: useBreakpointPropsType<number>;
|
|
14
|
+
infinite?: useBreakpointPropsType<boolean>;
|
|
15
|
+
autoplay?: useBreakpointPropsType<boolean>;
|
|
16
|
+
autoplayInterval?: useBreakpointPropsType<number>;
|
|
17
|
+
loop?: useBreakpointPropsType<boolean>;
|
|
18
|
+
duration?: useBreakpointPropsType<number>;
|
|
19
|
+
transition?: useBreakpointPropsType<TransitionProps["variant"]>;
|
|
20
|
+
easing?: useBreakpointPropsType<TransitionProps["easing"]>;
|
|
21
|
+
onChange?: (index: number, indexes: number[]) => void;
|
|
22
|
+
onNext?: (index: number, indexes: number[]) => void;
|
|
23
|
+
onPrev?: (index: number, indexes: number[]) => void;
|
|
24
|
+
};
|
|
25
|
+
declare const Carousel: React$1.ForwardRefExoticComponent<Omit<CarouselProps<TagComponentType>, "ref"> & React$1.RefAttributes<CarouselRef>>;
|
|
26
|
+
|
|
27
|
+
export { Carousel as default };
|
|
28
|
+
export type { CarouselProps, CarouselRef };
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { __rest } from 'tslib';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
import { useInterface, useBreakpointProps, Tag, Transition, animate } from '@xanui/core';
|
|
5
|
+
import { forwardRef, useState, Children, useRef, useEffect, useMemo, useImperativeHandle, useLayoutEffect } from 'react';
|
|
6
|
+
|
|
7
|
+
const Carousel = forwardRef((_a, ref) => {
|
|
8
|
+
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
9
|
+
var { children } = _a, rest = __rest(_a, ["children"]);
|
|
10
|
+
const [index, setIndex] = useState(0);
|
|
11
|
+
const childs = Children.toArray(children);
|
|
12
|
+
const total = childs.length;
|
|
13
|
+
const track = useRef(null);
|
|
14
|
+
const animating = useRef(() => { });
|
|
15
|
+
const state = useRef({ x: 0 });
|
|
16
|
+
const autoplayRef = useRef(null);
|
|
17
|
+
let [_k] = useInterface("Carousel", rest, {}), { slidesToShow, slidesToScroll, loop, autoplay, autoplayInterval, duration, transition, easing, onChange, onBeforeChange, onNext, onBeforeNext, onPrev, onBeforePrev } = _k, props = __rest(_k, ["slidesToShow", "slidesToScroll", "loop", "autoplay", "autoplayInterval", "duration", "transition", "easing", "onChange", "onBeforeChange", "onNext", "onBeforeNext", "onPrev", "onBeforePrev"]);
|
|
18
|
+
const _p = {};
|
|
19
|
+
if (slidesToShow)
|
|
20
|
+
_p.slidesToShow = slidesToShow;
|
|
21
|
+
if (slidesToScroll)
|
|
22
|
+
_p.slidesToScroll = slidesToScroll;
|
|
23
|
+
if (loop)
|
|
24
|
+
_p.loop = loop;
|
|
25
|
+
if (autoplay)
|
|
26
|
+
_p.autoplay = autoplay;
|
|
27
|
+
if (autoplayInterval)
|
|
28
|
+
_p.autoplayInterval = autoplayInterval;
|
|
29
|
+
if (duration)
|
|
30
|
+
_p.duration = duration;
|
|
31
|
+
if (transition)
|
|
32
|
+
_p.transition = transition;
|
|
33
|
+
if (easing)
|
|
34
|
+
_p.easing = easing;
|
|
35
|
+
const p = useBreakpointProps(_p);
|
|
36
|
+
slidesToShow = (_b = p.slidesToShow) !== null && _b !== void 0 ? _b : 1;
|
|
37
|
+
slidesToScroll = (_c = p.slidesToScroll) !== null && _c !== void 0 ? _c : 1;
|
|
38
|
+
autoplay = (_d = p.autoplay) !== null && _d !== void 0 ? _d : false;
|
|
39
|
+
autoplayInterval = (_e = p.autoplayInterval) !== null && _e !== void 0 ? _e : 3000;
|
|
40
|
+
loop = (_f = p.loop) !== null && _f !== void 0 ? _f : (autoplay ? true : false);
|
|
41
|
+
duration = (_g = p.duration) !== null && _g !== void 0 ? _g : 500;
|
|
42
|
+
transition = (_h = p.transition) !== null && _h !== void 0 ? _h : undefined;
|
|
43
|
+
easing = (_j = p.easing) !== null && _j !== void 0 ? _j : undefined;
|
|
44
|
+
if (slidesToShow > total) {
|
|
45
|
+
slidesToShow = total;
|
|
46
|
+
}
|
|
47
|
+
if (slidesToScroll > total) {
|
|
48
|
+
slidesToScroll = total;
|
|
49
|
+
}
|
|
50
|
+
if (slidesToShow <= 0) {
|
|
51
|
+
slidesToShow = 1;
|
|
52
|
+
}
|
|
53
|
+
if (slidesToScroll <= 0) {
|
|
54
|
+
slidesToScroll = 1;
|
|
55
|
+
}
|
|
56
|
+
if (slidesToScroll > slidesToShow) {
|
|
57
|
+
slidesToScroll = slidesToShow;
|
|
58
|
+
}
|
|
59
|
+
const goTo = (_index) => {
|
|
60
|
+
if (_index === index)
|
|
61
|
+
return;
|
|
62
|
+
if (_index < 0 || _index > total - slidesToShow)
|
|
63
|
+
return;
|
|
64
|
+
setIndex(_index);
|
|
65
|
+
const indexes = [];
|
|
66
|
+
for (let i = 0; i < slidesToShow; i++) {
|
|
67
|
+
indexes.push(_index + i);
|
|
68
|
+
}
|
|
69
|
+
onChange && onChange(_index, indexes);
|
|
70
|
+
const itemWidth = 100 / slidesToShow;
|
|
71
|
+
const trackEle = track.current;
|
|
72
|
+
const translate = itemWidth * _index;
|
|
73
|
+
animating.current();
|
|
74
|
+
animating.current = animate({
|
|
75
|
+
duration: duration,
|
|
76
|
+
from: { x: state.current.x },
|
|
77
|
+
to: { x: translate },
|
|
78
|
+
onUpdate: ({ x }) => {
|
|
79
|
+
state.current.x = x;
|
|
80
|
+
trackEle.style.transform = `translateX(-${x}%)`;
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
const next = () => {
|
|
85
|
+
let _index = index;
|
|
86
|
+
if (loop) {
|
|
87
|
+
if (_index >= total - slidesToShow) {
|
|
88
|
+
_index = 0;
|
|
89
|
+
}
|
|
90
|
+
else if (index + slidesToScroll > total - slidesToShow) {
|
|
91
|
+
_index = total - slidesToShow;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
_index = index + slidesToScroll;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
if (_index >= total - slidesToShow) {
|
|
99
|
+
_index = total - slidesToShow;
|
|
100
|
+
}
|
|
101
|
+
else if (index + slidesToScroll > total - slidesToShow) {
|
|
102
|
+
_index = total - slidesToShow;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
_index = index + slidesToScroll;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const indexes = [];
|
|
109
|
+
for (let i = 0; i < slidesToShow; i++) {
|
|
110
|
+
indexes.push(_index + i);
|
|
111
|
+
}
|
|
112
|
+
onNext && onNext(_index, indexes);
|
|
113
|
+
goTo(_index);
|
|
114
|
+
};
|
|
115
|
+
const prev = () => {
|
|
116
|
+
let _index = index;
|
|
117
|
+
if (loop) {
|
|
118
|
+
if (_index <= 0) {
|
|
119
|
+
_index = total - slidesToShow;
|
|
120
|
+
}
|
|
121
|
+
else if (index - slidesToScroll < 0) {
|
|
122
|
+
_index = 0;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
_index = index - slidesToScroll;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
if (_index <= 0) {
|
|
130
|
+
_index = 0;
|
|
131
|
+
}
|
|
132
|
+
else if (index - slidesToScroll < 0) {
|
|
133
|
+
_index = 0;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
_index = index - slidesToScroll;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const indexes = [];
|
|
140
|
+
for (let i = 0; i < slidesToShow; i++) {
|
|
141
|
+
indexes.push(_index + i);
|
|
142
|
+
}
|
|
143
|
+
onPrev && onPrev(_index, indexes);
|
|
144
|
+
goTo(_index);
|
|
145
|
+
};
|
|
146
|
+
const stopAutoplay = () => {
|
|
147
|
+
if (autoplayRef.current) {
|
|
148
|
+
clearTimeout(autoplayRef.current);
|
|
149
|
+
autoplayRef.current = null;
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const startAutoplay = () => {
|
|
153
|
+
stopAutoplay();
|
|
154
|
+
autoplayRef.current = setTimeout(next, autoplayInterval);
|
|
155
|
+
};
|
|
156
|
+
useEffect(() => {
|
|
157
|
+
if (!autoplay)
|
|
158
|
+
return;
|
|
159
|
+
startAutoplay();
|
|
160
|
+
return () => stopAutoplay();
|
|
161
|
+
}, [index, autoplay]);
|
|
162
|
+
const indexes = useMemo(() => {
|
|
163
|
+
const idx = [];
|
|
164
|
+
for (let i = 0; i < slidesToShow; i++) {
|
|
165
|
+
idx.push(index + i);
|
|
166
|
+
}
|
|
167
|
+
return idx;
|
|
168
|
+
}, [index, slidesToShow]);
|
|
169
|
+
useImperativeHandle(ref, () => ({
|
|
170
|
+
next,
|
|
171
|
+
prev,
|
|
172
|
+
goTo,
|
|
173
|
+
getIndex: () => index,
|
|
174
|
+
}));
|
|
175
|
+
useLayoutEffect(() => {
|
|
176
|
+
goTo(0);
|
|
177
|
+
}, []);
|
|
178
|
+
const startX = useRef(0);
|
|
179
|
+
const isDragging = useRef(false);
|
|
180
|
+
const handleStart = (x) => {
|
|
181
|
+
startX.current = x;
|
|
182
|
+
isDragging.current = true;
|
|
183
|
+
};
|
|
184
|
+
const handleEnd = (x) => {
|
|
185
|
+
if (!isDragging.current)
|
|
186
|
+
return;
|
|
187
|
+
const diff = x - startX.current;
|
|
188
|
+
if (diff > 50)
|
|
189
|
+
prev();
|
|
190
|
+
else if (diff < -50)
|
|
191
|
+
next();
|
|
192
|
+
isDragging.current = false;
|
|
193
|
+
};
|
|
194
|
+
return (jsx(Tag, Object.assign({}, props, { baseClass: 'carousel', ref: ref, sxr: {
|
|
195
|
+
width: "100%",
|
|
196
|
+
overflow: "hidden",
|
|
197
|
+
cursor: "grab",
|
|
198
|
+
touchAction: "pan-y",
|
|
199
|
+
position: "relative",
|
|
200
|
+
}, children: jsx(Tag, { baseClass: 'carousel-track', ref: track, sxr: {
|
|
201
|
+
display: "flex",
|
|
202
|
+
willChange: "transform",
|
|
203
|
+
flexDirection: "row",
|
|
204
|
+
}, onPointerDown: (e) => {
|
|
205
|
+
e.preventDefault();
|
|
206
|
+
handleStart(e.clientX);
|
|
207
|
+
}, onPointerUp: (e) => handleEnd(e.clientX), onTouchStart: (e) => {
|
|
208
|
+
e.preventDefault();
|
|
209
|
+
handleStart(e.touches[0].clientX);
|
|
210
|
+
}, onTouchEnd: (e) => handleEnd(e.changedTouches[0].clientX), onMouseEnter: () => {
|
|
211
|
+
stopAutoplay();
|
|
212
|
+
}, onMouseLeave: () => {
|
|
213
|
+
if (autoplay)
|
|
214
|
+
startAutoplay();
|
|
215
|
+
}, children: childs.map((child, index) => (transition ? jsx(Transition, { open: indexes.includes(index), variant: transition, easing: easing, duration: duration, initialTransition: false, children: jsx(Tag, { baseClass: 'carousel-item', sxr: {
|
|
216
|
+
p: 1,
|
|
217
|
+
userSelect: "none",
|
|
218
|
+
flexShrink: 0,
|
|
219
|
+
width: `${100 / slidesToShow}%`,
|
|
220
|
+
}, children: child }, `${index}`) }, index) : jsx(Tag, { baseClass: 'carousel-item', sxr: {
|
|
221
|
+
p: 1,
|
|
222
|
+
userSelect: "none",
|
|
223
|
+
flexShrink: 0,
|
|
224
|
+
width: `${100 / slidesToShow}%`,
|
|
225
|
+
}, children: child }, `${index}`))) }) })));
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
export { Carousel as default };
|
|
229
|
+
//# sourceMappingURL=index.js.map
|