Skip to content

Commit

Permalink
fix: replace react-select not working with SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jun 4, 2020
1 parent 327feca commit 3f621db
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 20 deletions.
4 changes: 3 additions & 1 deletion integrations/gatsby-theme-stories/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@
"theme-ui": "^0.3.1",
"@theme-ui/sidenav": "^0.3.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-helmet": "^6.0.0"
},
"devDependencies": {
"typescript": "^3.8.3"
},
"peerDependencies": {
"gatsby": "^2.22.10",
"react": "^16.13.1"
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"publishConfig": {
"access": "public"
Expand Down
2 changes: 0 additions & 2 deletions ui/editors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@
"react": "^16.13.1",
"react-color": "^2.17.0",
"react-dom": "^16.13.1",
"react-select": "^3.0.8",
"theme-ui": "^0.3.1"
},
"devDependencies": {
"@types/jest": "^25.1.2",
"@types/react-color": "^3.0.1",
"@types/react-select": "^3.0.10",
"@types/theme-ui": "^0.3.0",
"cross-env": "^5.2.1",
"eslint": "^6.5.1",
Expand Down
34 changes: 24 additions & 10 deletions ui/editors/src/OptionsEditor/OptionsEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
/** @jsx jsx */
import { jsx } from 'theme-ui';
import React, { ChangeEvent } from 'react';
import { Select } from 'theme-ui';
import styled from '@emotion/styled';
import {
ComponentControlOptions,
ControlTypes,
} from '@component-controls/specification';
import { normalizeOptions } from './utils';
import { PropertyEditor } from '../types';
import { useControlContext } from '../context';
import { RadiosEditor } from './RadiosEditor';
import { CheckboxEditor } from './CheckboxEditor';
import { addPropertyEditor } from '../prop-factory';

const OptionsSelect = styled(Select)({
color: 'black',
flexBasis: '100%',
});

/**
* Options control editor.
*/

export const OptionsEditor: PropertyEditor = ({ name, ...rest }) => {
const { control } = useControlContext<ComponentControlOptions>({
const { control, onChange } = useControlContext<ComponentControlOptions>({
name,
});
const { display } = control;
const { display, options, value } = control;

if (display === 'check' || display === 'inline-check') {
return <CheckboxEditor name={name} {...rest} />;
Expand All @@ -33,13 +40,20 @@ export const OptionsEditor: PropertyEditor = ({ name, ...rest }) => {
display === 'select' ||
display === 'multi-select'
) {
const { entries, selected } = normalizeOptions(options, value);
const handleChange = (e: ChangeEvent<HTMLSelectElement>) =>
onChange(name, [e.target.value]);

const selectValue = entries.filter(op => selected.includes(op.value));
const v: string = selectValue.length ? selectValue[0].value : '';
return (
<select
sx={{
color: 'black',
flexBasis: '100%',
}}
/>
<OptionsSelect value={v} onChange={handleChange}>
{entries.map(entry => (
<option key={entry.value} value={entry.value}>
{entry.label}
</option>
))}
</OptionsSelect>
);
}

Expand Down
108 changes: 101 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4773,6 +4773,16 @@
"@webassemblyjs/wast-parser" "1.9.0"
"@xtuc/long" "4.2.2"

"@webcomponents/[email protected]":
version "1.0.12"
resolved "https://registry.yarnpkg.com/@webcomponents/shadydom/-/shadydom-1.0.12.tgz#c52bfded1b03fb336b165224482bb0a049bcfbbb"
integrity sha512-UqtBMlM2hmTS9+GozVfzZ0LAq32CL9N/f5d0FlCs9c/GtFORPY5qj/ff5DwSyI/tIlKWk7W2F/eeCNJqKRZu7Q==

"@webcomponents/[email protected]":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@webcomponents/webcomponentsjs/-/webcomponentsjs-1.1.0.tgz#1392799c266fca142622a720176f688beb74d181"
integrity sha512-7toNyVlrl7vJnY3PU0eXIK1KWq8phfnEe1IwOdCMxkIl/BfUkUB2aaVs45R0LSx1qxHRnkqj0vlGtskUvKkNkA==

"@xtuc/ieee754@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@xtuc/ieee754/-/ieee754-1.2.0.tgz#eef014a3145ae477a1cbc00cd1e552336dceb790"
Expand Down Expand Up @@ -5791,7 +5801,7 @@ babel-plugin-transform-undefined-to-void@^6.9.4:
resolved "https://registry.yarnpkg.com/babel-plugin-transform-undefined-to-void/-/babel-plugin-transform-undefined-to-void-6.9.4.tgz#be241ca81404030678b748717322b89d0c8fe280"
integrity sha1-viQcqBQEAwZ4t0hxcyK4nQyP4oA=

[email protected]:
[email protected], babel-polyfill@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.26.0.tgz#379937abc67d7895970adc621f284cd966cf2153"
integrity sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM=
Expand Down Expand Up @@ -5887,7 +5897,7 @@ babel-preset-typescript-vue@^1.0.3:
"@babel/preset-typescript" "^7.3.3"
vue-template-compiler "^2.6.11"

babel-runtime@^6.23.0, babel-runtime@^6.26.0:
babel-runtime@^6.23.0, babel-runtime@^6.26.0, babel-runtime@^6.6.1:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
integrity sha1-llxwWGaOgrVde/4E/yM3vItWR/4=
Expand Down Expand Up @@ -7518,6 +7528,11 @@ core-js-pure@^3.0.0, core-js-pure@^3.0.1:
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.6.5.tgz#c79e75f5e38dbc85a662d91eea52b8256d53b813"
integrity sha512-lacdXOimsiD0QyNf9BC/mxivNJ/ybBGJXQFKzRekp1WTHoVUWsUHEn+2T8GJAzzIhyOuXA+gOxCVN3l+5PLPUA==

core-js@^1.0.0:
version "1.2.7"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"
integrity sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY=

core-js@^2.4.0, core-js@^2.5.0, core-js@^2.6.11, core-js@^2.6.5:
version "2.6.11"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.11.tgz#38831469f9922bded8ee21c9dc46985e0399308c"
Expand Down Expand Up @@ -9523,6 +9538,19 @@ fb-watchman@^2.0.0:
dependencies:
bser "2.1.1"

fbjs@^0.8.16:
version "0.8.17"
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.17.tgz#c4d598ead6949112653d6588b01a5cdcd9f90fdd"
integrity sha1-xNWY6taUkRJlPWWIsBpc3Nn5D90=
dependencies:
core-js "^1.0.0"
isomorphic-fetch "^2.1.1"
loose-envify "^1.0.0"
object-assign "^4.1.0"
promise "^7.1.1"
setimmediate "^1.0.5"
ua-parser-js "^0.7.18"

figgy-pudding@^3.4.1, figgy-pudding@^3.5.1:
version "3.5.2"
resolved "https://registry.yarnpkg.com/figgy-pudding/-/figgy-pudding-3.5.2.tgz#b4eee8148abb01dcf1d1ac34367d59e12fa61d6e"
Expand Down Expand Up @@ -11139,6 +11167,11 @@ hmac-drbg@^1.0.0:
minimalistic-assert "^1.0.0"
minimalistic-crypto-utils "^1.0.1"

hoist-non-react-statics@^2.1.1:
version "2.5.5"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz#c5903cf409c0dfd908f388e619d86b9c1174cb47"
integrity sha512-rqcy4pJo55FTTLWt+bU8ukscqHeE/e9KWvsOW2b/a3afxQZhwkQdT1rPPCJ0rYXdj4vNcasY8zHTH+jF/qStxw==

hoist-non-react-statics@^3.3.0:
version "3.3.2"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45"
Expand Down Expand Up @@ -12298,7 +12331,7 @@ is-ssh@^1.3.0:
dependencies:
protocols "^1.1.0"

is-stream@^1.1.0:
is-stream@^1.0.1, is-stream@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ=
Expand Down Expand Up @@ -12442,6 +12475,14 @@ isobject@^4.0.0:
resolved "https://registry.yarnpkg.com/isobject/-/isobject-4.0.0.tgz#3f1c9155e73b192022a80819bacd0343711697b0"
integrity sha512-S/2fF5wH8SJA/kmwr6HYhK/RI/OkhD84k8ntalo0iJjZikgq1XFvR5M8NPT1x5F7fBwCG3qHfnzeP/Vh/ZxCUA==

isomorphic-fetch@^2.1.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
integrity sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=
dependencies:
node-fetch "^1.0.1"
whatwg-fetch ">=0.10.0"

isstream@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
Expand Down Expand Up @@ -13690,7 +13731,7 @@ longest@^1.0.1:
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
integrity sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=

loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0:
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.3.1, loose-envify@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
Expand Down Expand Up @@ -14685,6 +14726,14 @@ [email protected], node-fetch@^2.3.0, node-fetch@^2.5.0, node-fetch@^2.6.0:
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==

node-fetch@^1.0.1:
version "1.7.3"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
integrity sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==
dependencies:
encoding "^0.1.11"
is-stream "^1.0.1"

[email protected]:
version "0.9.0"
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.9.0.tgz#d624050edbb44874adca12bb9a52ec63cb782579"
Expand Down Expand Up @@ -16370,7 +16419,7 @@ promise.prototype.finally@^3.1.0:
es-abstract "^1.17.0-next.0"
function-bind "^1.1.1"

promise@^7.0.1:
promise@^7.0.1, promise@^7.1.1:
version "7.3.1"
resolved "https://registry.yarnpkg.com/promise/-/promise-7.3.1.tgz#064b72602b18f90f29192b8b1bc418ffd1ebd3bf"
integrity sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==
Expand All @@ -16392,6 +16441,15 @@ promzard@^0.3.0:
dependencies:
read "1"

[email protected]:
version "15.6.1"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.1.tgz#36644453564255ddda391191fb3a125cbdf654ca"
integrity sha512-4ec7bY1Y66LymSUOH/zARVYObB23AT2h8cf6e/O6ZALB/N0sqZFEx7rq6EYPX2MkOdKORuooI/H5k9TlR4q7kQ==
dependencies:
fbjs "^0.8.16"
loose-envify "^1.3.1"
object-assign "^4.1.1"

prop-types@^15.5.0, prop-types@^15.5.10, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
Expand Down Expand Up @@ -16769,6 +16827,13 @@ react-animate-height@^2.0.20:
classnames "^2.2.5"
prop-types "^15.6.1"

[email protected]:
version "3.0.1"
resolved "https://registry.yarnpkg.com/react-click-outside/-/react-click-outside-3.0.1.tgz#6e77e84d2f17afaaac26dbad743cbbf909f5e24c"
integrity sha512-d0KWFvBt+esoZUF15rL2UBB7jkeAqLU8L/Ny35oLK6fW6mIbOv/ChD+ExF4sR9PD26kVx+9hNfD0FTIqRZEyRQ==
dependencies:
hoist-non-react-statics "^2.1.1"

react-clientside-effect@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/react-clientside-effect/-/react-clientside-effect-1.2.2.tgz#6212fb0e07b204e714581dd51992603d1accc837"
Expand Down Expand Up @@ -17081,6 +17146,11 @@ react-select@^3.0.8:
react-input-autosize "^2.2.2"
react-transition-group "^4.3.0"

[email protected]:
version "16.2.0"
resolved "https://registry.yarnpkg.com/react-shadow/-/react-shadow-16.2.0.tgz#5655121ee7443e60b407ef3b1eb23a67233c787e"
integrity sha512-75y6w8LW1fg2BaIiR94sdL+B5YtCWGXPXqrzQNmBXvwOIN4bzqZAIbXagHMBO7rGrJWTqpDReeQoGsuicDJ57g==

react-side-effect@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/react-side-effect/-/react-side-effect-2.1.0.tgz#1ce4a8b4445168c487ed24dab886421f74d380d3"
Expand All @@ -17096,6 +17166,20 @@ react-sizeme@^2.6.7:
shallowequal "^1.1.0"
throttle-debounce "^2.1.0"

react-styled-select@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/react-styled-select/-/react-styled-select-3.0.0.tgz#5dc45ef1c92bb8b27c52b8ad52814c10d3378dec"
integrity sha512-wS8pJLrCn+Mj+FrzCxrZzjrYBnDege6eacYMulHCTrLYLhUyDl51xGQ0X3pLTSEdn5zlNMDqQWi7azpfE99UDA==
dependencies:
"@webcomponents/shadydom" "1.0.12"
"@webcomponents/webcomponentsjs" "1.1.0"
babel-polyfill "^6.26.0"
babel-runtime "^6.6.1"
prop-types "15.6.1"
react-click-outside "3.0.1"
react-shadow "16.2.0"
uuid "^3.1.0"

react-switch@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/react-switch/-/react-switch-5.0.1.tgz#449277f4c3aed5286fffd0f50d5cbc2a23330406"
Expand Down Expand Up @@ -18321,7 +18405,7 @@ set-value@^2.0.0, set-value@^2.0.1:
is-plain-object "^2.0.3"
split-string "^3.0.1"

setimmediate@^1.0.4:
setimmediate@^1.0.4, setimmediate@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
integrity sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=
Expand Down Expand Up @@ -19997,6 +20081,11 @@ typescript@^3.9.3:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.3.tgz#d3ac8883a97c26139e42df5e93eeece33d610b8a"
integrity sha512-D/wqnB2xzNFIcoBG9FG8cXRDjiqSTbG2wd8DMZeQyJlP1vfTkIxH4GKveWaEBYySKIg+USu+E+EDIR47SqnaMQ==

ua-parser-js@^0.7.18:
version "0.7.21"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.21.tgz#853cf9ce93f642f67174273cc34565ae6f308777"
integrity sha512-+O8/qh/Qj8CgC6eYBVBykMrNtp5Gebn4dlGD/kKXVkJNDwyrAwSIqwz8CDf+tsAIWVycKcku6gIXJ0qwx/ZXaQ==

uglify-js@^2.6.1:
version "2.8.29"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd"
Expand Down Expand Up @@ -20452,7 +20541,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=

[email protected], uuid@^3.0.0, uuid@^3.0.1, uuid@^3.3.2, uuid@^3.4.0:
[email protected], uuid@^3.0.0, uuid@^3.0.1, uuid@^3.1.0, uuid@^3.3.2, uuid@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
Expand Down Expand Up @@ -20841,6 +20930,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f"
integrity sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==

whatwg-fetch@>=0.10.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz#fc804e458cc460009b1a2b966bc8817d2578aefb"
integrity sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q==

whatwg-mimetype@^2.1.0, whatwg-mimetype@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"
Expand Down

0 comments on commit 3f621db

Please sign in to comment.