-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Responsive): add component #1872
Conversation
c11e5b3
to
4cbd612
Compare
Codecov Report
@@ Coverage Diff @@
## master #1872 +/- ##
==========================================
+ Coverage 99.76% 99.76% +<.01%
==========================================
Files 148 149 +1
Lines 2561 2584 +23
==========================================
+ Hits 2555 2578 +23
Misses 6 6
Continue to review full report at Codecov.
|
62abdd4
to
6e17efd
Compare
package.json
Outdated
@@ -130,7 +130,7 @@ | |||
"satisfied": "^1.1.0", | |||
"semantic-ui-css": "^2.2.11", | |||
"simulant": "^0.2.2", | |||
"sinon": "^2.1.0", | |||
"sinon": "^2.3.8", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sinon should be updated to support value
:
sandbox.stub().value()
6e17efd
to
8e3209c
Compare
src/addons/Breakpoint/Breakpoint.js
Outdated
const { only = '' } = this.props | ||
const points = only.replace('large screen', 'largeScreen').split(' ') | ||
|
||
return _.some(points, point => _.invoke(this, point)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this.point
get defined?
_.invoke(this, point))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It equals to this[point]()
, while point
is an element of array that is splitted from only
prop. The idea is to call breakpoint matchers (methods) until match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will prefix breakpoints with is
, it will be easier to read
src/addons/Breakpoint/Breakpoint.js
Outdated
// Helpers | ||
// ---------------------------------------- | ||
|
||
visible = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's prefix bools isVisible
Also need merge with |
…React into feat/breakpoint
…antic-UI-React into feat/breakpoint # Conflicts: # src/addons/Breakpoint/Breakpoint.d.ts # src/addons/Breakpoint/Breakpoint.js # src/addons/Breakpoint/index.d.ts # src/lib/customPropTypes.js # test/specs/addons/Breakpoint/Breakpoint-test.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@levithomason I've prefixed all methods that returns boolean
with is
. It will be easier to understand what it makes.
NamingPer the request for naming, I've renamed this component: <Responsive breakpoints={} /> I think this makes sense as many devs should be familiar with Bootstrap's "responsive utilities", which are classes for the same purpose. breakpointsI'm not sure about this prop. It seems it would be most helpful to set this at the LESS/CSS level instead. If we did allow overriding a specific <Responsive minWidth={400} />
<Responsive maxWidth={800} /> What is the use case for overriding the value of |
NamingAgree about breakpointsI've add it because widths that SUI uses are variables and it can be possible, that someone override them in own theme. Thats why I think we allow to change used values. |
…React into feat/breakpoint # Conflicts: # package.json
…antic-UI-React into feat/breakpoint # Conflicts: # test/specs/addons/Breakpoint/Breakpoint-test.js
Oh, I see. I was mistaken in thinking the The only issue I see here is that users with custom CSS breakpoints in their theme would expect this component to respect them, but it won't. Imagine I set my theme to have a mobile breakpoint of 400px: <Column only='mobile' /> // only <400px (uses my LESS/CSS value)
<Responsive only='mobile' /> // only <300px (uses defaultProps value) I'm worried about adding complexity and configuration to the theming process. It is quite cumbersome already. My next suggestion was going to be that we should add CSS support for these utilties, however, it looks like SUI core isn't fond of responsive visibility or responsive utilities. There is a design decision to not permit them. While I don't agree, chances of getting into CSS core are minimal. I'm still not comfortable merging this while we have two components with |
You justly paid attention to these things, but unfortunately I see no other way to solve this problem. I want to solve the problem with useless rendering, |
What if we remove the const mediaQueries = { tablet: { minWidth: 768, maxWidth: 992 } }
<Responsive {...mediaQueries.tablet} /> I would be OK with this as it doesn't suggest to the user that there is any relation between Responsive's |
I will think about this, but |
You're right, it is very intuitive. If it used the same CSS as the Grid it would be a no brainer. Since they will produce 2 different behaviors, I think it becomes unintuitive. One hack I didn't want to mention was somehow creating a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@levithomason I refactored it to minWidth
and maxWidth
and added breakpoints as static properties. Also, it now uses eventStack
and RAF for resize
handler.
Cool, seems like a good middle ground 👍 Thanks much for the cooperative spirit. |
Released in |
* feat(Breakpoint): add component * feat(Breakpoint): add component * feat(Breakpoint): add component * style(Breakpoint): prefix bools with "is" * refactor(Breakpoint): rename Responsive * style(mixed): fix lint issues * feat(Responsive): refactor component * revert(customPropTypes): reverned unnecessary changes
Why?
This component is the idea picked from my production project.
Breakpoint
uses syntax fromGrid
's device visibility, but has two important differences:Grid
markup, so two close items can have a different visibilityWarning
Breakpoint
adds a listener towindow
that can cause a performance issue, however it will be solved by #1733.P.S. Better ideas about the component's name are welcome.