2.0.0 • Published 3 years ago
reactjs-timezone-select v2.0.0
See live Demo
Installing
npm install reactjs-timezone-select
or
yarn add reactjs-timezone-selectUsage
import React, { useState } from "react";
import { SelectTimezone } from "reactjs-timezone-select";
function App() {
const [value, setValue] = useState("America/Chicago");
const customStyles = {
option: (provided, state) => ({
...provided,
borderBottom: "1px dotted pink",
color: state.isSelected ? "red" : "blue",
padding: 20,
}),
};
return (
<SelectTimezone
name="Custom timezone"
label="Select Timezone"
value={value}
onChange={({ label, value }) => setValue(value)}
containerStyles={{ width: 300 }}
labelStyles={{ color: "red" }}
selectStyles={customStyles}
optionLabelFormat={(timezone) =>
`${timezone.name} - ${timezone.abbreviation}`
}
defaultToSystemTimezone
/>
);
}Props
label- label for SelectTimezonestring, i.e.'Select Timezone'value- Initial Timezonestring, i.e.'America/Chicago'onChange-(selectedOption) => void- Object format of
selectedOptionparameter:
{ label: 'America/Chicago', value: 'America/Chicago' }- Object format of
defaultToSystemTimezone- Set default value to user's system timezonebooleancontainerStyles- Set styles for SelectTimezone's parent containerlabelStyles- Set styles for SelectTimezone's labelselectStyles- Set styles for SelectTimezone select, get more inforeact-select-stylesoptionLabelFormat- Formatting option with many timezone fields(timezoneObject) => string- Example format of
timezoneObject:
{ "name": "America/Chicago", "alternativeName": "Central Time", "group": [ "America/Chicago", "America/Indiana/Knox", "America/Indiana/Tell_City", "America/Menominee", "America/North_Dakota/Beulah", "America/North_Dakota/Center", "America/North_Dakota/New_Salem", "US/Central", "America/Knox_IN", "US/Indiana-Starke" ], "continentCode": "NA", "continentName": "North America", "countryName": "United States", "countryCode": "US", "mainCities": [ "Chicago", "Houston", "San Antonio", "Dallas" ], "rawOffsetInMinutes": -360, "abbreviation": "CST", "rawFormat": "-06:00 Central Time - Chicago, Houston, San Antonio, Dallas", "currentTimeOffsetInMinutes": -300, "currentTimeFormat": "-05:00 Central Time - Chicago, Houston, San Antonio, Dallas" }- Example format of
Any other
react-selectprops
Contributing
Pull requests are always welcome!