-
Notifications
You must be signed in to change notification settings - Fork 351
Added a custom Option type and extended the select and added a few new classes for typography #1060
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
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| use sailfish::runtime::{Buffer, Render}; | ||
| use std::ops::{Deref, DerefMut}; | ||
|
|
||
| // This is a custom wrapper around Option so we can implement render for it | ||
| pub struct CustomOption<T>(Option<T>); | ||
|
|
||
| impl<T> Default for CustomOption<T> { | ||
| fn default() -> Self { | ||
| Self(None) | ||
| } | ||
| } | ||
|
|
||
| impl<T> CustomOption<T> { | ||
| pub fn new(value: T) -> Self { | ||
| Self(Some(value)) | ||
| } | ||
| } | ||
|
|
||
| impl<T> From<T> for CustomOption<T> { | ||
| fn from(value: T) -> Self { | ||
| Self(Some(value)) | ||
| } | ||
| } | ||
|
|
||
| impl<T> Deref for CustomOption<T> { | ||
| type Target = Option<T>; | ||
|
|
||
| fn deref(&self) -> &Self::Target { | ||
| &self.0 | ||
| } | ||
| } | ||
|
|
||
| impl<T> DerefMut for CustomOption<T> { | ||
| fn deref_mut(&mut self) -> &mut Self::Target { | ||
| &mut self.0 | ||
| } | ||
| } | ||
|
|
||
| impl<T: Render> Render for CustomOption<T> { | ||
| fn render(&self, b: &mut Buffer) -> Result<(), sailfish::RenderError> { | ||
| match &self.0 { | ||
| Some(value) => value.render(b), | ||
| None => Ok(()), | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using a mixin for this would prevent the repetition.
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 me update this. I haven't used mixins before
Uh oh!
There was an error while loading. Please reload this page.
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.
classes are better than mixins, mixings generate a ton of repetitive css code, while classes inherit and cascade. That's why bootstrap has
.btnand.btn-primaryclasses separately..btnstyles a lot of the button while.btn-primaryjust changes the color, which is just one or two lines of css.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.
@extend is also an option that minimizes css code (same as having two classes) and reduces the number of classes an element needs to take. If we do go with two classes here we should have the _typographic class .text-gradient then a utility class for all the gradients so they can be applies as text color, background color, border color ect.