llorentegerman / simple-flexbox Goto Github PK
View Code? Open in Web Editor NEWA simple way to make responsive layouts using Flexbox in React
License: MIT License
A simple way to make responsive layouts using Flexbox in React
License: MIT License
How about supporting semantic elements?
I think all we need to change is Layout's element div
to semantic elements.
return (<div style={layoutStyles} {...ownProps}>
{this.props.children}
</div>);
I have example link : https://github.com/nachoaIvarez/flexbox-react/blob/master/src/Flexbox.jsx
I've tried to get offsetWidth
from Column's ref.current, but it prints undefined
.
We need to support ref.
It's not works
<Column ref={this.thisComponent}>
<div>test</div>
<div>test2</div>
</Column>
It works
<div ref={this.thisComponent}>
<div>test</div>
<div>test2</div>
</div>
By the way material-ui supports ref this way although it uses hook
https://github.com/mui-org/material-ui/blob/5301c24c3be1023efcec7e33bd7e7f030a87c0cb/packages/material-ui/src/Typography/Typography.js#L122-L163
const Typography = React.forwardRef(function Typography(props, ref) {
const {
align = 'inherit',
classes,
className,
color = 'initial',
component,
display = 'initial',
gutterBottom = false,
noWrap = false,
paragraph = false,
theme,
variant = 'body1',
variantMapping = defaultVariantMapping,
...other
} = props;
const Component =
component ||
(paragraph ? 'p' : variantMapping[variant] || defaultVariantMapping[variant]) ||
'span';
return (
<Component
className={clsx(
classes.root,
{
[classes[variant]]: variant !== 'inherit',
[classes[`color${capitalize(color)}`]]: color !== 'initial',
[classes.noWrap]: noWrap,
[classes.gutterBottom]: gutterBottom,
[classes.paragraph]: paragraph,
[classes[`align${capitalize(align)}`]]: align !== 'inherit',
[classes[`display${capitalize(display)}`]]: display !== 'initial',
},
className,
)}
ref={ref}
{...other}
/>
);
});
I'm having this issue while building my Gatsby website, any idea how to fix it?
`
"window" is not available during server side rendering.
See our docs page for more info on this error: https://gatsby.dev/debug-html
497 | return _extends({}, style, window.innerWidth <= +key ? { flexDirection: value } : {});
498 | }
499 | return _extends({}, style, window.innerWidth <= +key ? value : {});
| ^
500 | }, {});
501 |
502 | var classNames = ((className || '') + ' ' + breakpointsClassNames.join(' ')).trim();
WebpackError: ReferenceError: window is not defined
index.js:499
node_modules/simple-flexbox/build/index.js:499:35
index.js:485 Layout.render
node_modules/simple-flexbox/build/index.js:485:14
`
You may think the property name componentRef
is not a familiar word.
You may want to change it to ref
, but It seemed Class Component does not allowed to use ref
as a prop's name. (https://reactjs.org/warnings/special-props.html)
You may want to change it to Functional Component with React.forwadRef()
(for this we should update react >= 16.3 )
Note: I pull requested this issue see: #3
When I type npm install @types/simple-flexbox the "Not found" error occurred so we need to support type declaration for it.
Apart from it I made my own declaration file :
/// <reference types="react" />
declare module 'simple-flexbox' {
declare class Column extends React.Component<ColumnProps> {}
declare class Row extends React.Component<RowProps> {}
declare interface ColumnProps {
onClick?: (e: React.MouseEvent) => void;
className?: string
style?: React.CSSProperties
flexGrow?: number
wrap?: boolean
flex?: string,
flexShrink?: number
flexBasis?: string
breakpoints?: object
reverse?: boolean
children: any
vertical?: 'start' | 'center' | 'end' | 'spaced' | 'space-between' | 'around' | 'space-around' | 'space-evenly'
horizontal?: 'start' | 'center' | 'end' | 'stretch'
justifyContent?: 'start' | 'flex-start' | 'center' | 'end' | 'flex-end' | 'spaced' | 'space-between' | 'around' | 'space-around' | 'space-evenly'
alignItems?: 'start' | 'center' | 'end' | 'stretch' | 'baseline'
alignSelf?: 'start' | 'center' | 'end' | 'stretch' | 'baseline'
alignContent?: 'start' | 'flex-start' | 'center' | 'end' | 'flex-end' | 'spaced' | 'space-between' | 'around' | 'space-around' | 'stretch'
}
declare interface RowProps {
onClick?: (e: React.MouseEvent) => void;
className?: string
style?: React.CSSProperties
wrap?: boolean
reverse?: boolean
flex?: string
flexGrow?: number
flexShrink?: number
flexBasis?: string
breakpoints?: object
children: any
vertical?: 'start' | 'center' | 'end' | 'spaced' | 'baseline'
horizontal?: 'start' | 'center' | 'end' | 'spaced' | 'space-between' | 'around' | 'space-around' | 'space-evenly'
justifyContent?: 'start' | 'flex-start' | 'center' | 'end' | 'flex-end' | 'spaced' | 'space-between' | 'around' | 'space-around' | 'space-evenly'
alignItems?: 'start' | 'center' | 'end' | 'stretch' | 'baseline'
alignSelf?: 'start' | 'center' | 'end' | 'stretch' | 'baseline'
alignContent?: 'start' | 'flex-start' | 'center' | 'end' | 'flex-end' | 'spaced' | 'space-between' | 'around' | 'space-around' | 'stretch'
}
}
Steps to solve this issue
typescript-playground
|
| ├── src
| ├── public
| ├── node_modules
| ├── @types
| ├── simple-flexbox
| ├── index.d.ts
"typeRoots": ["./node_modules/@types", "./@types"]
in your tsconfig.json{
"compilerOptions": {
"target": "es5",ue,
"skipLibCheck": true,
"..."
"typeRoots": ["./node_modules/@types", "./@types"]
},
}
Can webpack be moved to dev-dependencies? This is causing issues in my project which uses a newer version of react
How about adding form element as a semantic element?
It uses as a container of inputs so we should add it into our code.
element: PropTypes.oneOf([**_'form',_** 'article', 'aside', 'div', 'figure', 'footer', 'header', 'main', 'nav', 'section'])
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.