Skip to content

Commit

Permalink
Merge pull request #1598 from cozy/preact
Browse files Browse the repository at this point in the history
feat: Remove preact
  • Loading branch information
ptbrowne authored Oct 12, 2020
2 parents 401e445 + 1c481ca commit dc07983
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 63 deletions.
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Check the [styleguide](https://docs.cozy.io/cozy-ui/styleguide) to see all the v

## React components

Check out [UI components](https://docs.cozy.io/cozy-ui/react/) to see how to use ready made (p)React components.
Check out [UI components](https://docs.cozy.io/cozy-ui/react/) to see how to use ready made React components.

## Usage

Expand All @@ -38,7 +38,7 @@ import 'cozy-ui/transpiled/react/stylesheet.css'
<Button />
```

You're now ready to use [Cozy UI's (p)React components](https://docs.cozy.io/cozy-ui/react/)
You're now ready to use [Cozy UI's React components](https://docs.cozy.io/cozy-ui/react/)

### Utility classes

Expand Down
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@
"npm-run-all": "4.1.5",
"postcss-cli": "6.1.3",
"postcss-loader": "2.1.6",
"preact": "8.4.2",
"preact-portal": "1.1.3",
"pretty": "2.0.0",
"prop-types": "15.7.2",
"puppeteer": "2.1.1",
Expand Down Expand Up @@ -160,8 +158,6 @@
"cozy-device-helper": "1.10.0",
"cozy-doctypes": "^1.69.0",
"piwik-react-router": "^0.8.2",
"preact": "^8.3.1",
"preact-portal": "^1.1.3",
"puppeteer": "1.20.0",
"react": "^16.8.6",
"react-dom": "^16.8.6"
Expand Down
28 changes: 14 additions & 14 deletions react/AppTile/__snapshots__/AppTile.spec.jsx.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AppTile component should render correctly an app 1`] = `
<BaseI18n
<I18n
defaultLang="en"
dictRequire={[Function]}
lang="en"
Expand Down Expand Up @@ -34,11 +34,11 @@ exports[`AppTile component should render correctly an app 1`] = `
slug="test"
version="3.0.3"
/>
</BaseI18n>
</I18n>
`;

exports[`AppTile component should render correctly an app in maintenance 1`] = `
<BaseI18n
<I18n
defaultLang="en"
dictRequire={[Function]}
lang="en"
Expand Down Expand Up @@ -81,11 +81,11 @@ exports[`AppTile component should render correctly an app in maintenance 1`] = `
slug="test2"
version="3.0.3-beta7483"
/>
</BaseI18n>
</I18n>
`;

exports[`AppTile component should render correctly an app with iconToLoad (icon being fetching) 1`] = `
<BaseI18n
<I18n
defaultLang="en"
dictRequire={[Function]}
lang="en"
Expand Down Expand Up @@ -122,11 +122,11 @@ exports[`AppTile component should render correctly an app with iconToLoad (icon
slug="test2"
version="3.0.3-beta7483"
/>
</BaseI18n>
</I18n>
`;

exports[`AppTile component should render correctly an app with iconToLoad if isMobile 1`] = `
<BaseI18n
<I18n
defaultLang="en"
dictRequire={[Function]}
lang="en"
Expand Down Expand Up @@ -164,11 +164,11 @@ exports[`AppTile component should render correctly an app with iconToLoad if isM
slug="test2"
version="3.0.3-beta7483"
/>
</BaseI18n>
</I18n>
`;

exports[`AppTile component should render correctly an app without developer property 1`] = `
<BaseI18n
<I18n
defaultLang="en"
dictRequire={[Function]}
lang="en"
Expand All @@ -193,11 +193,11 @@ exports[`AppTile component should render correctly an app without developer prop
slug="test"
version="3.0.3"
/>
</BaseI18n>
</I18n>
`;

exports[`AppTile component should render correctly an installed app 1`] = `
<BaseI18n
<I18n
defaultLang="en"
dictRequire={[Function]}
lang="en"
Expand Down Expand Up @@ -232,11 +232,11 @@ exports[`AppTile component should render correctly an installed app 1`] = `
slug="test2"
version="3.0.3-beta7483"
/>
</BaseI18n>
</I18n>
`;

exports[`AppTile component should render correctly an installed app without icon provided 1`] = `
<BaseI18n
<I18n
defaultLang="en"
dictRequire={[Function]}
lang="en"
Expand Down Expand Up @@ -269,5 +269,5 @@ exports[`AppTile component should render correctly an installed app without icon
slug="test"
version="3.0.3"
/>
</BaseI18n>
</I18n>
`;
16 changes: 4 additions & 12 deletions react/I18n/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const DEFAULT_LANG = 'en'
export const I18nContext = React.createContext()

// Provider root component
class BaseI18n extends Component {
export class I18n extends Component {
constructor(props) {
super(props)
this.init(this.props)
Expand Down Expand Up @@ -58,32 +58,24 @@ class BaseI18n extends Component {
}
}

BaseI18n.propTypes = {
I18n.propTypes = {
lang: PropTypes.string.isRequired, // current language.
polyglot: PropTypes.object, // A polyglot instance.
dictRequire: PropTypes.func, // A callback to load locales.
context: PropTypes.string, // current context.
defaultLang: PropTypes.string // default language. By default is 'en'
}

BaseI18n.defaultProps = {
I18n.defaultProps = {
defaultLang: DEFAULT_LANG
}

BaseI18n.childContextTypes = {
I18n.childContextTypes = {
t: PropTypes.func,
f: PropTypes.func,
lang: PropTypes.string
}

class PreactI18n extends BaseI18n {
componentWillReceiveProps(nextProps) {
this.UNSAFE_componentWillReceiveProps(nextProps)
}
}

export const I18n = process.env.USE_PREACT ? PreactI18n : BaseI18n

// higher order decorator for components that need `t` and/or `f`
export const translate = () => WrappedComponent => {
const Wrapper = props => {
Expand Down
19 changes: 5 additions & 14 deletions react/Portal/index.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
let Portal
if (process.env.USE_PREACT) {
try {
Portal = require('preact-portal')
} catch (e) {
// We need this try/catch for webpack not to error if preact-portal
// is not found
}
} else {
const ReactDOM = require('react-dom')
Portal = ({ into, children }) => {
const targetElement = document.querySelector(into)
return ReactDOM.createPortal(children, targetElement)
}
import ReactDOM from 'react-dom'

const Portal = ({ into, children }) => {
const targetElement = document.querySelector(into)
return ReactDOM.createPortal(children, targetElement)
}

export default Portal
9 changes: 2 additions & 7 deletions react/Viewer/ViewerExposer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
let defaultViewer
if (process.env.USE_PREACT) {
defaultViewer = ''
} else {
defaultViewer = require('./index').default
}
import DefaultViewer from './index'

export default defaultViewer
export default DefaultViewer
10 changes: 0 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13757,16 +13757,6 @@ posthtml@^0.9.2:
posthtml-parser "^0.2.0"
posthtml-render "^1.0.5"

[email protected]:
version "1.1.3"
resolved "https://registry.yarnpkg.com/preact-portal/-/preact-portal-1.1.3.tgz#22cdd3ecf6ad9aaa3f830607a9c6591de90aedb7"
integrity sha512-rE0KG2b7ggIly4VVsSm7+WmQmG/EoUZzBOed2IbycyaFIArOvz+yab/8RBoDogA0JWZuTsbMTStR41Ghc+5m7Q==

[email protected]:
version "8.4.2"
resolved "https://registry.yarnpkg.com/preact/-/preact-8.4.2.tgz#1263b974a17d1ea80b66590e41ef786ced5d6a23"
integrity sha512-TsINETWiisfB6RTk0wh3/mvxbGRvx+ljeBccZ4Z6MPFKgu/KFGyf2Bmw3Z/jlXhL5JlNKY6QAbA9PVyzIy9//A==

prelude-ls@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
Expand Down

0 comments on commit dc07983

Please sign in to comment.