Is anyone using semantic-ui with emberjs? - css

Just wondering if there is anyone out there who has tried to use semantic-ui with emberjs?
Were there any major pitfalls? semantic-ui looks nice and regular ... which for a relative novice to browser development, looks like a big plus vs the other 'all-inclusive' css frameworks ...

I haven't used Semantic UI with Ember but I've implemented and built individual jQuery plugins and css frameworks with Ember.
CSS & HTML
The css in Semantic UI doesn't affect Ember because Ember is a javascript framework and it's css classes all have the 'ember-' prefix. Though, it's worth noting that the css wildcard selector [class*='input'] would still target .ember-input. Thus, make sure Semantic UI's framework's selectors are efficient and non-invasive. You could probably make Semantic UI's pre-given class names easier to work with by extending Ember views or using components with tagNames and classNames set in the views/components. Alternatively, you could use register Handlebars helper that return html. For example:
Em.Handlebars.helper('button', function(unescapedText) {
var type = Handlebars.Utils.escapeExpression(unescapedText);
buttonString = '<button class="semantic-ui-button">' + text + '</button>';
return new Handlebars.SafeString(buttonString);
});
Obviously, this is a very simplified answer. You could get more complex and use block handlebars helpers with content in it (e.g. a dropdown list component with any number of different LIs in it). You could even create an Ember object which contains a key-value-pair map for all the Semantic UI classes to look up the class, tagName, and more of each Semantic UI component. For example:
App.SemanticUi = Em.Object.create({
components: [
button: {
class: 'semantic-ui-button',
tagName: 'button',
}
],
});
App.Handlebars.helper('button', function() {
// Some logic ...
var class = App.SemanticUi.get('components')[button];
// Some more logic...
});
This is just a theoretical use case.
Javascript
As for the javascript, you could optimize Semantic UI's js files for Ember by rebuilding them as components. However, I would not recommend this because it will be hard to maintain as Semantic UI releases new builds and features. Your best option is probably to load the plugins with your Ember App and then run additional customizable functions (like those found in Semantic UI's examples directory) on didInsertElement like so:
App.HomeView = Em.View.extend({
customFunctions: function() {
// Custom Semantic UI logic with DOM targeting here
$('.ui.dropdown').dropdown({
// Dropdown stuff, etc
});
}.on('didInsertElement'),
});
If you come across issues with Semantic UI not adding module functions correctly, I would look at the order in which the plugin and the elements in the DOM are loading and interacting with one another. Also, if you're running your Ember Apps on Rails or Yeoman, or a similar setup, the asset pipeline might interfere here.
If you're planning on using semantic UI just for the CSS then you shouldn't have any issues. Otherwise, I hope someone can give you a more specific answer with regards to the javascript modules.

Related

Using third party libraries in Svelte custom component

I want to create a web component using svelte. To create a web component it's necessary to include the svelte tag option
<svelte:options tag="{"my-custom-component}"></svelte:options>
It creates a custom component with that name but doesn't work properly because we have to provide this tag for all the child components as well! I added it to all the child components but it still doesn't work, turns out I use third-party libraries and I don't know any way to have that option there!
Is there a way to create the custom components with svelte which includes third-party libraries?
You can use regular svelte components (including third party) ones inside your component.
But you'll need to compile those with different compiler settings in your rollup/webpack config.
And due to the nature of scoped styling in web components (Shadow DOM) the css won't work in these components. So it depends on the library if it still works.
You might be able to turn off scoped styling in the future:
Issue #1748: Custom element without shadow DOM
But scoped styling could have been the reason why you wanted/needed webcomponents in the first place.

react-jss does not cache css classes

I use Mui (material ui) List and in the ListItem I have a custom component that's a bit complex (has other components + states, can collapse or expand, etc.).
I use react-jss (injectSheet(styles)(component)), and I see that for every element that I am adding in the list, there is a new Css that's injected into the page header.
I thought that there is a caching added in react-jss but it looks that I was wrong.
Could you please advice how can I cache the Css using react-jss? Also, if this is not an option, and I have to use jss + plugins then an example of jss setup with caching plugin will help.
Thanks for the help!
Static styles injected through react-jss are reused between all component instances. If you use function values (dynamic styles) there will be no reuse as you can have different values on each element.

Dynamic styles with bootstrap and css modules

I have a React project that is using CSS modules (for components) + React-Bootstrap with CDN-hosted CSS.
I have a requirement that when my app loads (per user), I make a call to an endpoint to get a dynamic style guide.
For simplicity, it would be something like this:
{
"color_background": "#edeae3",
"color_error": "#9e2d2d",
"color_highlight": "#69b5ce",
"color_success": "#498e49",
}
The app should then be rendered in those colors. I know there is the ability to customize static Bootstrap styling (e.g. http://getbootstrap.com/customize/), but I'm not sure how to do it dynamically.
Any guidance would be appreciated.

How to manage clashing third party CSS

I'm working on a web application which is using Materialize as a front-end framework along with Kendo UI for the grid component.
I'm hitting problems in cases where both Kendo UI and Materialize have styles for the same element - for example they both override the styling on check boxes - this results in a broken layout due to the clash.
One option I realize is to pick either Materialize or Kendo UI and drop the other... however I would like to avoid this if possible as they in the most part have complemented each others weaknesses well.
If it was simply one element here or there putting specific overrides in would be an option however with the scale of the two frameworks this would be a maintenance nightmare as when one changed the overrides would possibly have to be refactored.
Are there any ways to solve this issue that I am missing?
One way to workaround such a clash is to build your MaterializeCSS to include only the parts you so need for your project.
For instance, if you do not need the buttons styling of MaterializeCSS, you could simply, via sass, compile the materialize.scss and cherry pick buttons out of the file.
If going down the path of building your custom .css of Materialize is a long short for you, you can try using materialize.khophi.co (Disclaimer: I built it).
Find more about how to customize your MaterializeCSS: http://materializecss.com/getting-started.html
I know it's usually suggested not to duplicate code, and you want to try steering away from overrides, but would it be possible to find the section of css you like (i.e. select box from materialize) and copy that in to a new custom css file, renaming the selector so you can use it seperately from Materialize/Kendo UI?
You can manually edit the stylesheet of eighter party. Take the non-minified CSS, and prepend every base path with a short prefix:
.card {
....
}
becomes
.mat.card {
....
}
That way, for every materialize style, you use .mat before anything. Or, if you mainly use materialize, do the same thing for Kendo UI.
This is a lot of pain, but would solve your issue.

How can I apply a UI framework explicitly rather than globally?

I want to use a UI framework for the admin backend in a Wordpress plugin. Unfortunately, most frameworks apply many styles globally rather than explicitly. These global resets and overrides work well for sites built from the ground up, but they can wreak havoc when implemented into an existing architecture such as the Wordpress backend.
I am looking for a UI framework that is (1) designed to be or (2) can be overridden to be applied only to a given region of the page such as by a class name on a parent div. This would allow me to apply the framework to my specific options regions, while leaving the rest of the backend untouched.
I recently started working with YUI's Pure.css, which has an almost non-existant global reset paired with explicit classes all starting with the 'pure-' prefix. However, this framework is a little more lightweight than I'd like. I am looking for something a little more feature-rich along the lines of Bootstrap or Semantic UI.
You can prefix Bootstrap for example, either way you can handle it with less or prefix them yourself with this tool http://www.css-prefix.com/ since this should work for any framwork
for less you'll need something like this
.yourpluginname-bs {
#import (less) url("bootstrap.css");
}

Resources