Skip to content

Commit

Permalink
more doc; working on MUI integration
Browse files Browse the repository at this point in the history
  • Loading branch information
benkeen committed Dec 2, 2024
1 parent e156bd5 commit 9943628
Show file tree
Hide file tree
Showing 36 changed files with 839 additions and 98 deletions.
22 changes: 5 additions & 17 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
## Developer Notes

This was a very old script which I revamped in Dec 2024 to bring it into the 21st century. Version `4.0.0` now uses Typescript,
modern rollup + babel and jest for testing, plus uses this crazy new thing called "hooks" in React.
This was a very old script which I revamped in Dec 2024 to bring it into the 21st century. Version `4.0.0` now uses Turborepo, Typescript,
modern rollup + babel, jest for testing, modern React, Docusaurus for the doc, eslint and prettier.

The dev environment is functional but needs work.

`yarn build` -> builds the script.
`yarn` - bootstraps the app. Also builds it.
`yarn test` - runs the tests. Note, if you're altering the code run `yarn && yarn test` (see "Ugly bits" below).

Ugly bits:

- The country-regions data set is very large, so to keep bundle sizes down, the rollup build for this script parses
the data and minifies it as much as it can. That's done in via a custom rollup plugin. It works fine, but makes local dev a
bit awkward, e.g. running the tests while tweaking the code. For that you have to run `yarn && yarn test` to first rebuild,
then run the tests - and the tests are ran on the `/dist` result. Awkward. This'd be nice to rethink.
- The `/example` folder is a mess. It's very data, requires a bit of custom setup to bootstrap both the main repo and that. Plus,
just like the tests it won't auto-reload when you change the source: you have to do a rebuild and even restart the server.
- needs linting + prettier set up.
`pnpm install` - bootstraps the monorepo
`npm run dev` - starts dev mode.
`npm run test` - runs the tests

### Notes for next 4.x release

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/docs/Demos/BasicUsage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Basic Usage
sidebar_position: 1
---

import BasicUsage from '@site/src/components/examples/BasicUsage';
import BasicUsage from '@site/src/components/demos/BasicUsage';

Let's get started! This first demo shows the basic usage of the script, using minimal settings. As you can see, you're
responsible for tracking state, but the tools handles rendering the appropriate countries and regions.
Expand Down
59 changes: 59 additions & 0 deletions apps/docs/docs/Demos/features/CountryBlacklist.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: Country Blacklist
sidebar_position: 9
---

import CountryBlacklist from '@site/src/components/demos/features/CountryBlacklist';

The `blacklist` prop omits those countries from the dropdown. This demo hides all countries starting with `A`.
The values are found in the `countryShortCode` value in the [source data package](https://github.com/country-regions/country-region-data/blob/master/data.json).

<CountryBlacklist />

---

```tsx
import React, { useState } from 'react';
import { CountryDropdown, RegionDropdown } from 'react-country-region-selector';

const CountryBlacklist = () => {
const [country, setCountry] = useState('');
const [region, setRegion] = useState('');

return (
<>
<CountryDropdown
value={country}
onChange={(val) => setCountry(val)}
// highlight-start
blacklist={[
'AF',
'AX',
'AL',
'DZ',
'AS',
'AD',
'AO',
'AI',
'AQ',
'AG',
'AR',
'AM',
'AW',
'AU',
'AT',
'AZ',
]}
// highlight-end
/>
<RegionDropdown
country={country}
value={region}
onChange={(val) => setRegion(val)}
/>
</>
);
};

export default CountryBlacklist;
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Country Whitelist
sidebar_position: 8
---

import CountryWhitelist from '@site/src/components/examples/CountryWhitelist';
import CountryWhitelist from '@site/src/components/demos/features/CountryWhitelist';

The `whitelist` prop on the CountryDropdown component limits the listed countries to those that you specify. The
values are found in the `countryShortCode` value in the [source data package](https://github.com/country-regions/country-region-data/blob/master/data.json).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Custom Default Option Labels
sidebar_position: 4
---

import CustomDefaultOptionLabels from '@site/src/components/examples/CustomDefaultOptionLabels';
import CustomDefaultOptionLabels from '@site/src/components/demos/features/CustomDefaultOptionLabels';

In case you want to localize the strings or just change the defaults, take a look at the following props:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Disable Empty Region Field
sidebar_position: 3
---

import DisableEmptyRegionField from '@site/src/components/examples/DisableEmptyRegionField';
import DisableEmptyRegionField from '@site/src/components/demos/features/DisableEmptyRegionField';

When the user hasn't selected a country, nothing's going to show up in the Region dropdown. If you want to disable it,
use the `disableWhenEmpty` prop.
Expand Down
42 changes: 42 additions & 0 deletions apps/docs/docs/Demos/features/DisableFields.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: Disable Fields
sidebar_position: 12
---

import DisableFields from '@site/src/components/demos/features/DisableFields';

The `disabled` prop can be used on either component.

<DisableFields />

---

```tsx
import React, { useState } from 'react';
import { CountryDropdown, RegionDropdown } from 'react-country-region-selector';

const DisableFields = () => {
const [country, setCountry] = useState('');
const [region, setRegion] = useState('');

return (
<>
<CountryDropdown
value={country}
onChange={(val) => setCountry(val)}
// highlight-next-line
disabled={true}
/>
<RegionDropdown
country={country}
value={region}
onChange={(val) => setRegion(val)}
// highlight-next-line
disabled={true}
/>
</>
);
};

export default DisableFields;
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Name, ID, Class attributes
sidebar_position: 5
---

import NameIdClassAttrs from '@site/src/components/examples/NameIdClassAttrs';
import NameIdClassAttrs from '@site/src/components/demos/features/NameIdClassAttrs';

This demo shows how to set `name`, `id` and `class` attributes on each component.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: No Default Option
sidebar_position: 2
---

import NoDefaultOption from '@site/src/components/examples/NoDefaultOption';
import NoDefaultOption from '@site/src/components/demos/features/NoDefaultOption';

The `showDefaultOption` boolean prop (default: `true`) can be set on both `CountryDropdown` and `RegionDropdown`. When set to
`false` the default "Select Country" / "Select Region" option won't appear.
Expand Down
47 changes: 47 additions & 0 deletions apps/docs/docs/Demos/features/RegionBlacklist.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: Region Blacklist
sidebar_position: 11
---

import RegionBlacklist from '@site/src/components/demos/features/RegionBlacklist';

The `blacklist` prop on the RegionDropdown copmonent lets you hide specific regions from the list. This hides
Alberta and BC from Canada's regions and Washington and Texas from US. The
values are found in the `countryShortCode` value in the [source data package](https://github.com/country-regions/country-region-data/blob/master/data.json).

<RegionBlacklist />

---

```tsx
import React, { useState } from 'react';
import { CountryDropdown, RegionDropdown } from 'react-country-region-selector';

const RegionBlacklist = () => {
const [country, setCountry] = useState('');
const [region, setRegion] = useState('');

return (
<>
<CountryDropdown
value={country}
onChange={(val) => setCountry(val)}
whitelist={['CA', 'US']}
/>
<RegionDropdown
country={country}
value={region}
onChange={(val) => setRegion(val)}
// highlight-start
blacklist={{
CA: ['AB', 'BC'],
US: ['WA', 'TX'],
}}
// highlight-end
/>
</>
);
};

export default RegionBlacklist;
```
47 changes: 47 additions & 0 deletions apps/docs/docs/Demos/features/RegionWhitelist.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
title: Region Whitelist
sidebar_position: 10
---

import RegionWhitelist from '@site/src/components/demos/features/RegionWhitelist';

The `whitelist` prop on the `RegionDropdown` component limits the listed regions to those that you specify. The
values are found in the `countryShortCode` value in the [source data package](https://github.com/country-regions/country-region-data/blob/master/data.json).
Note the order will always be alphabetical.

<RegionWhitelist />

---

```tsx
import React, { useState } from 'react';
import { CountryDropdown, RegionDropdown } from 'react-country-region-selector';

const RegionWhitelist = () => {
const [country, setCountry] = useState('');
const [region, setRegion] = useState('');

return (
<>
<CountryDropdown
value={country}
onChange={(val) => setCountry(val)}
whitelist={['CA', 'US']}
/>
<RegionDropdown
country={country}
value={region}
onChange={(val) => setRegion(val)}
// highlight-start
whitelist={{
CA: ['AB', 'BC'],
US: ['WA', 'TX'],
}}
// highlight-end
/>
</>
);
};

export default RegionWhitelist;
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Shortcode Labels
sidebar_position: 6
---

import ShortcodeLabels from '@site/src/components/examples/ShortcodeLabels';
import ShortcodeLabels from '@site/src/components/demos/features/ShortcodeLabels';

The `CountryDropdown` and `RegionDropdown` fields both let you customize the display values for the
dropdowns. Either `full` (default) or `short`. You can mix and match. Note that this is purely for the _label_.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Shortcode Values
sidebar_position: 7
---

import ShortcodeLabels from '@site/src/components/examples/ShortcodeLabels';
import ShortcodeLabels from '@site/src/components/demos/features/ShortcodeLabels';

The `valueType` prop on both components alters the _value_ of each option to be a short code rather than the full
country or region name, like with the visible label. Note that when you use `valueType` as `short` for the
Expand Down
13 changes: 13 additions & 0 deletions apps/docs/docs/Demos/features/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Features
---

This section demos all the various features of the script. You can read the descriptions in the sidebar in the left if
that works for you, but here's a simple mapping of prop to demo - in case that's more useful.

| `CountryDropdown` | `RegionDropdown` |
| --------------------------- | --------------------------- |
| [`value`](../BasicUsage) | [`value`](../BasicUsage) |
| [`onChange`](../BasicUsage) | [`onChange`](../BasicUsage) |

[TODO]
11 changes: 11 additions & 0 deletions apps/docs/docs/Demos/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Demos
---

The following pages demo all the features of the script.

- [Basic Usage](./BasicUsage): start here for a quick demonstration of how to use the components.
- [Features](./Features): this section contains demos of all the available features.
- [Integrations](./Integrations): by default, the components output by this package output plain HTML `<select>` and
`<option>` elements. This section shows how you can use the package with other libraries like Material UI, using their
own components instead.
14 changes: 14 additions & 0 deletions apps/docs/docs/Demos/integrations/MaterialUI.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Material UI
sidebar_position: 1
---

import MaterialUI from '@site/src/components/demos/integrations/MaterialUI';

<MaterialUI />

---

```tsx

```
33 changes: 2 additions & 31 deletions apps/docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { themes as prismThemes } from 'prism-react-renderer';
import type { Config } from '@docusaurus/types';
import type * as Preset from '@docusaurus/preset-classic';

// This runs in Node.js - Don't use client-side code here (browser APIs, JSX...)

const config: Config = {
title: 'react-country-region-selector',
tagline: '',
Expand Down Expand Up @@ -48,16 +46,9 @@ const config: Config = {
],

themeConfig: {
// image: 'img/docusaurus-social-card.jpg',
navbar: {
title: 'React-Country-Region-Selector',
title: 'react-country-region-selector',
items: [
{
type: 'docSidebar',
sidebarId: 'tutorialSidebar',
position: 'left',
label: 'Documentation',
},
{
href: 'https://github.com/country-regions/react-country-region-selector',
label: 'GitHub',
Expand All @@ -67,29 +58,9 @@ const config: Config = {
},
footer: {
style: 'dark',
// links: [
// {
// title: 'Docs',
// items: [
// {
// label: 'Tutorial',
// to: '/docs/intro',
// },
// ],
// },
// {
// title: 'Community',
// items: [
// {
// label: 'Stack Overflow',
// href: 'https://stackoverflow.com/questions/tagged/docusaurus',
// },
// ],
// },
// ],
},
/*
theme$j as dracula,
theme$j as dracula,
theme$i as duotoneDark,
theme$h as duotoneLight,
theme$g as github,
Expand Down
Loading

0 comments on commit 9943628

Please sign in to comment.