Is it possible make each story to have its own css in storybook? - styling

As I know, storybook will build one single "ALL IN ONE" css file and includes it in the html. Is it possible make each story to have its own css only? Like the picture below, each section can have the corresponding css resource.

Related

How to render assets (images) in rich text coming from Contentful

I've set up Contentful as the headless CMS of my blog. Everything works, except rendering assets (in my case images specifically). My blog is built using Symfony and uses Twig for templating.
This is how (a part of the) content is currently rendered:
I'm using Contentful's default rich text renderer for Twig, as described here. Unfortunately, it doesn't say anything about assets. But given that there's an EmbeddedImage class available, I would expect support for images.
What step am I missing?
You need to define a custom renderer for the assets in the same way as described for a custom heading here.
The reason why assets don't work "out of the box" is that the renderer can't know what type of asset is being returned. For example, is it a .jpg, .mp4, .wav file etc. You may have a variety of different assets in your Rich Text and will need to render the different asset files accordingly to your HTML.
The full list of node types you can define custom renderers for is here.

How to include javascript and css files in Hybris?

I am trying to use a 3rd party javascript control, Owl Carousel. The way I am reading the documentations is this:
In the zip file from Owl Carousel there is a folder called owlcarousel that contains the javascript and another folder that contains all the supporting files which need to be copied to /modules/base-accelerator/yacceleratorstorefront/web/webroot/_ui/responsive/common. Then I simply need to go into the javaScript.tag file and add this line towards the end of the file:
<script src="${commonResourcePathHtml}/owlcarousel/owl.carousel.min.js"></script>
Upon trying that, I get all sorts of loading errors and no images are display, even without using the control. So my question is:
What is the correct approach to include a 3rd party javascript?
Is there any way to control which pages actually get a javascript file or do simply ALL the pages get ALL the javascript includes?
See if "Storefront Web Application Deconstructed" will help: https://help.sap.com/viewer/4c33bf189ab9409e84e589295c36d96e/1905/en-US/8af03fda8669101491e4aac2acaeb2dd.html
web/webroot
_ui: Contains the JavaScript and CSS styling for the current theme.
shared/js: Shared JavaScript used by desktop and responsive pages.
responsive/common: Commonly used style sheets, JavaScript libraries and images.
responsive/theme-alpha: The blue theme definition.
responsive/theme-lambda: The black theme definition.
WEB-INF
_ui-src: Contains JS testing, full libraries, and the Less files used to generate the CSS for a theme.
common/tld: The tag library descriptor files for the CMS and ycommerce tags.
config: Spring application context files.
lib: The libraries required by the storefront.
messages: The localization files.
tags: The tags that are used within views.
views: The JSP pages, fragments and CMS components.

AEM 6.2 (Drag Component Here) Parsys height 0px

I am using AEM 6.2 and trying to create a parsys component in crx, using the code below
However, the height of this parsys, in edit mode, comes as 0px.
Attached are the screenshots.
When I manually change the height to some values eg. 40px, it looks fine.
Note: I am not using any client library for the above page. (no css and js)
Futher, All sample sites like geomatrix etc have parsys showing correctly.
Could anyone guide me with what I am doing wrong?
I think that the problem is outside the component or any of the code shown here.
I think what's happening is that the css style for the div that gives the droptarget placeholder its dimensions is not loading.
That's loaded as part of the AEM authoring client libraries which you should be inheriting from the foundation page component.
Examine your page component's sling:resourceSuperType property. It should point to either wcm/foundation/components/page or wcm/foundation/components/page or inherit from a component that does.
If that is set then you have may have blocked one of the scripts within it, quite possibly head.html.
Include following code in the head section of the page component's rendering script.
<!--/* Include Adobe Dynamic Tag Management libraries for the header
<sly data-sly-include="/libs/cq/cloudserviceconfigs/components/servicelibs/servicelibs.jsp" data-sly-unwrap/>
*/-->
<!--/* Initializes the Experience Manager authoring UI */-->
<sly data-sly-include="/libs/wcm/core/components/init/init.jsp" data-sly-unwrap/>
For resolving your issue, you need to include init.jsp in the first before writing down the parsys code. I mean write like this.
<head>
<sly data-sly-include='/libs/wcm/core/components/init/init.jsp' />
</head>
<body>
<sly data-sly-resource="${'par' #resourceType='foundation/components/parsys'}" />
</body>
I think #l-klement pointed it out correctly that the problem is outside component. When I rename the landingpage.html file to body.html it starts working fine. I think this may be because of different files like head.html etc present at wcm/foundation/components/page which is required to provide proper styling and load certain required client libraries which assigns proper styling to parsys.
If the above is true, my next question would be, How can I have my own head.html, body.html, header.html, footer.html etc files without compromising with the parsys styling?

Conflicts between Custom theme CSS and Liferay CSS

I am trying to customize the Liferay UI by using custom theme using base as as "_Styled" theme.
I have my own css files which I coped to _diff/css folder of theme and imported them "custom.css" file .However its breaking the presentation of liferay.In my custom CSS I have styles defined for all the standard tags like body,div etc which is impacting the liferay UI too.
How can I resolve this conflict? Thanks in advance!
Quick (and not the best) solution is to remove contents of liferays css file (for example "base.css") and save this empty file in /diff/css/ folder of your theme. This way the base.css will get overriden with your new empty file and thus no styles will get loaded. And your custom.css will be the only stylesheet that is taken into account.
Well, of course it all has an effect on the rest of Liferay as well. Liferay provides quite a bit of the HTML DOM of your page, and if you change the presentation of all of those elements, you'll have to take care to style Liferay's elements too.
Is this a conflict? No. Let's go for the simplest case: You declare div {color:green;}. Of course, now everything, your components as well as Liferay's components, use green text. If you only want to style your own portlets, you might want to specify some portlets: div.portlet-my-own-application {color:green;}
I know that color is a too simple usecase, but I hope it illustrates the solution strategy.
Rather than following Artem Khojoyan's suggestion to override Liferay's base.css, I'd recommend to take a look at the resulting css, what's effective etc., and simplify your own css - adapt it to be used within Liferay - by inspecting the effective CSS for every elements that looks off. Firebug or any of it's relatives are your friend.
I'm afraid, with the details "I'm doing something which has an effect on Liferay UI" there's nothing much more to help you. In fact, I'd hope that what you do has an effect on Liferay's UI... You'll just need to find the proper CSS code
Ideally if your styles are loaded from custom.css, then will overwrite liferay default styles.
In some cases, to overwrite a style in css, you can use !important
for example, liferay default style
body {
background-color: #fff
}
You can specify your style to consider irrespective of order of loading
body {
background-color: red !important;
}

Is there a function in Orchard CMS that will retrieve the Theme directory?

I have images in my theme (in the Content/ directory) and I want to show them in different places.
My current approach is : <img src="#Url.Content("~/Themes/MyTheme/Content/Images/image.gif")" />
This works, but is not very maintainable (what if I want to switch themes, etc).
Is there an built in method, something like GetCurrentThemeDirectory() that would return the directory so I could do or something like that?
Edit: from mdm's comment, I realize that changing the theme isn't a valid concern. I really just want to avoid typing out the url for every reference
Where are you referencing the image from? Module? Another theme?
If it is from the theme that has the image, then you don't need to worry about switching themes. If it is from another theme, then the image should be a part of the theme. If it is from a module, then it would make sense to store the image as part of the module or override it in the theme (see below).
If you wanted to have the image as part of the theme, then you could have the module return a 'default' shape and then override that in the theme. There really shouldn't be any reason to reference the theme's images from a module or vice versa.
Edit after your edit
In the themes I've written, I've followed what the Orchard authors do. Rather than using <img> tags, images are placed in Styles/images. They can then be referenced using the CSS background-image attribute.
In Views/Branding.cshtml:
<div id="header"></div>
<h1 id="branding">#WorkContext.CurrentSite.SiteName</h1>
And then in site.css:
#header {
/* snip */
background-image: url(images/header.png);
/* snip */
}
Themes/TheAdmin/site.css contains plenty more examples of this method.

Resources