-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
172 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
() => { | ||
const [startDate, setStartDate] = useState(new Date()); | ||
return ( | ||
<DatePicker | ||
showIcon | ||
selected={startDate} | ||
onChange={(date) => setStartDate(date)} | ||
icon="fa fa-calendar" | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
() => { | ||
const [startDate, setStartDate] = useState(new Date()); | ||
return ( | ||
<DatePicker | ||
showIcon | ||
selected={startDate} | ||
onChange={(date) => setStartDate(date)} | ||
icon={ | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="1em" | ||
height="1em" | ||
viewBox="0 0 48 48" | ||
> | ||
<mask id="ipSApplication0"> | ||
<g fill="none" stroke="#fff" strokeLinejoin="round" strokeWidth="4"> | ||
<path strokeLinecap="round" d="M40.04 22v20h-32V22"></path> | ||
<path | ||
fill="#fff" | ||
d="M5.842 13.777C4.312 17.737 7.263 22 11.51 22c3.314 0 6.019-2.686 6.019-6a6 6 0 0 0 6 6h1.018a6 6 0 0 0 6-6c0 3.314 2.706 6 6.02 6c4.248 0 7.201-4.265 5.67-8.228L39.234 6H8.845l-3.003 7.777Z" | ||
></path> | ||
</g> | ||
</mask> | ||
<path | ||
fill="currentColor" | ||
d="M0 0h48v48H0z" | ||
mask="url(#ipSApplication0)" | ||
></path> | ||
</svg> | ||
} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
const CalendarIcon = ({ icon, className }) => { | ||
const defaultClass = "react-datepicker__calendar-icon"; | ||
|
||
if (React.isValidElement(icon)) { | ||
return React.cloneElement(icon, { | ||
className: `${icon.props.className || ""} ${defaultClass} ${className}`, | ||
}); | ||
} | ||
|
||
if (typeof icon === "string") { | ||
return ( | ||
<i | ||
className={`${defaultClass} ${icon} ${className}`} | ||
aria-hidden="true" | ||
/> | ||
); | ||
} | ||
|
||
// Default SVG Icon | ||
return ( | ||
<svg | ||
className="react-datepicker__calendar-icon" | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 448 512" | ||
> | ||
<path d="M96 32V64H48C21.5 64 0 85.5 0 112v48H448V112c0-26.5-21.5-48-48-48H352V32c0-17.7-14.3-32-32-32s-32 14.3-32 32V64H160V32c0-17.7-14.3-32-32-32S96 14.3 96 32zM448 192H0V464c0 26.5 21.5 48 48 48H400c26.5 0 48-21.5 48-48V192z" /> | ||
</svg> | ||
); | ||
}; | ||
|
||
CalendarIcon.propTypes = { | ||
icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), | ||
className: PropTypes.string, | ||
}; | ||
|
||
CalendarIcon.defaultProps = { | ||
className: "", | ||
}; | ||
|
||
export default CalendarIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from "react"; | ||
import { mount } from "enzyme"; | ||
import CalendarIcon from "../src/calendar_icon"; | ||
import { IconParkSolidApplication } from "./helper_components/calendar_icon"; | ||
|
||
beforeAll(() => { | ||
jest.spyOn(console, "error").mockImplementation(() => {}); | ||
}); | ||
|
||
afterAll(() => { | ||
console.error.mockRestore(); | ||
}); | ||
|
||
describe("CalendarIcon", () => { | ||
it("renders a custom SVG icon when provided", () => { | ||
const wrapper = mount( | ||
<CalendarIcon showIcon icon={<IconParkSolidApplication />} />, | ||
); | ||
expect( | ||
wrapper.find('[data-testid="icon-park-solid-application"]'), | ||
).toHaveLength(1); | ||
}); | ||
|
||
it("renders a FontAwesome icon when provided", () => { | ||
const wrapper = mount(<CalendarIcon showIcon icon="fa-example-icon" />); | ||
expect(wrapper.find("i.fa-example-icon")).toHaveLength(1); | ||
}); | ||
|
||
it("does not render an icon when none is provided", () => { | ||
const wrapper = mount(<CalendarIcon showIcon />); | ||
expect(wrapper.find("svg.react-datepicker__calendar-icon")).toHaveLength(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from "react"; | ||
|
||
export function IconParkSolidApplication(props) { | ||
return ( | ||
<svg | ||
data-testid="icon-park-solid-application" | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="1em" | ||
height="1em" | ||
viewBox="0 0 48 48" | ||
{...props} | ||
> | ||
<mask id="ipSApplication0"> | ||
<g fill="none" stroke="#fff" strokeLinejoin="round" strokeWidth="4"> | ||
<path strokeLinecap="round" d="M40.04 22v20h-32V22" /> | ||
<path | ||
fill="#fff" | ||
d="M5.842 13.777C4.312 17.737 7.263 22 11.51 22c3.314 0 6.019-2.686 6.019-6a6 6 0 0 0 6 6h1.018a6 6 0 0 0 6-6c0 3.314 2.706 6 6.02 6c4.248 0 7.201-4.265 5.67-8.228L39.234 6H8.845l-3.003 7.777Z" | ||
/> | ||
</g> | ||
</mask> | ||
<path | ||
fill="currentColor" | ||
d="M0 0h48v48H0z" | ||
mask="url(#ipSApplication0)" | ||
/> | ||
</svg> | ||
); | ||
} |