How to disable 'Docs' tab in storybook? - storybook

How do i disable the 'docs' (addons-docs) tab on a per story basis?
I've tried adding the key values below to a story, but nothing seems to work.
parameters: {
docs: { disable: true, hidden: true }
},
I'm running Storybook 5.3.8.

This will hide docs panel and show canvas only:
parameters: {
previewTabs: {
'storybook/docs/panel': {
hidden: true,
},
},
},
Tabs container will be hidden, if you have only one tab

I managed to do it with the v6.0.0-alpha.28 (#storybook/*#next) with the new parameters:
previewTabs: {
docs: { hidden: true },
}
I've added the default config on preview.js:
addParameters({
previewTabs: {
docs: {
hidden: false
},
canvas: {
title: 'Story',
hidden: false,
},
},
})
and also repositioned the Docs to be the first tab on manager.js:
import { addons } from '#storybook/addons';
addons.setConfig({
previewTabs: {
'storybook/docs/panel': { index: -1 },
},
});
Hope it works on the long term :)
Enjoy!

Inside your MyStory.stories.j[t]sx file
To hide the "Docs" tab:
export default {
title: 'YourTitle',
parameters: {
previewTabs: {
'storybook/docs/panel': { hidden: true }
},
viewMode: 'canvas',
}
};
To hide the "Canvas" tab:
export default {
title: 'YourTitle',
parameters: {
previewTabs: {
canvas: { hidden: true},
},
viewMode: 'docs',
}
};
The viewMode: 'docs/canvas' it's necessary to set the default tab in that view, otherwise storybook will show the last tab opened in the previous view.

Old Answers give you the technique to hide the docs but if someone will change the URL from story to docs, it will show the results, so I am giving you the way to perfectly remove the docs tab.
1st Method
If you added the #storybook/addon-docs package to your package.json and added it into .storybook/main.js ( addon array ) then remove it and restart your storybook webpack server.
2nd Method
In the latest version of the storybook, it recommends to add an essentials addon package coming from storybook that contains multiple addons such as actions, backgrounds, controls, docs, viewport, toolbars.
So if you installed that package and added it into the .storybook/main.js addon array then you disable it with the below code.
Replace your code from
module.exports = {
addons: [
...,
'#storybook/addon-essentials',
],
};
TO
module.exports = {
addons: [
...,
{
name: '#storybook/addon-essentials',
options: {
docs: false,
},
},
],
};

Related

Why are custom height measures not working in my tailwind.config.js?

I have been working on a project with NextJS and Tailwind CSS.
I need to use the height class h-96 for a couple of components, but since it is not default-defined I decided to added it to my tailwind.config.js like this:
/** #type {import('tailwindcss').Config} */
module.exports = {
content: [
'./app/**/*.{js,ts,jsx,tsx}',
'./pages/**/*.{js,ts,jsx,tsx}',
'./ui/**/*.{js,ts,jsx,tsx}',
'./components/**/*.{js,ts,jsx,tsx}',
],
theme: {
extend: {
height: {
'96': '24rem',
},
// https://vercel.com/design/color
colors: {
vercel: {
primaryGreen: '#92c700',
primaryBlue: '#111871',
primaryPurple: '#5c068c',
secondaryPurple: '#6d0793',
},
},
},
},
};
I was expecting to be able to use h-96 but it seems that the configuration in the tailwind.config.js file are not been applied to the project.
NOTE: I also tried to set the height like this:
height: {
96: '24rem',
},
since the linting auto-corrected it for me, but this didn't work either.
h-96 is already defined in the tailwind css classes. You can update the h-96 default value in the tailwind.config.js in the following way.
/** #type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {
height: {
'96':'124rem'
}
// ...
},
},
plugins: [],
}
Also , if you are just using it for couple of components, you can also directly change the values in the components itself like h-[124rem].
More info here
Height 96 (h-96) is a default theme. Since you are attempting to override a default, you must add it directly under the theme tab because you are not 'extending' anything, but rather changing the default configuration.
Source: Here
Try this:
/** #type {import('tailwindcss').Config} */
module.exports = {
content: [
'./app/**/*.{js,ts,jsx,tsx}',
'./pages/**/*.{js,ts,jsx,tsx}',
'./ui/**/*.{js,ts,jsx,tsx}',
'./components/**/*.{js,ts,jsx,tsx}',
],
theme: {
height: {
96: '24rem',
},
extend: {
// https://vercel.com/design/color
colors: {
vercel: {
primaryGreen: '#92c700',
primaryBlue: '#111871',
primaryPurple: '#5c068c',
secondaryPurple: '#6d0793',
},
},
},
},
};

Enable hover only on top/bottom/left/right

I'm trying to create a variant in Tailwind file configuration.
What I would like to have is something like hover:border-l-4 hover:border-green-400, so a class that enables a border on the left (or only on top / bottom / right).
So I create this inside tailwind.config.js:
module.exports = {
purge: {
enabled: process.env.NODE_ENV === 'production',
content: ['./src/**/*.html', './src/**/*.{js,ts,jsx,tsx}'],
},
darkMode: false,
theme: {
extend: {
colors: {
...
},
},
borderLeft: (theme) => ({}),
...
},
variants: {
extend: {
borderLeft: ['hover', 'focus']
},
},
plugins: [],
}
It doesn't work. I get TypeError: variantsValue is not iterable.
I didn't find anything useful in the documentation page.
Checkout docs on tailwind.
variants: {
extend: {
borderWidth: ['hover'],
}
}
From here, hover:border-l-4 hover:border-green-400 will work.

Tailwind: How to access default things after configuring the config file?

In order to have the user be able to select their color scheme in my website, I added a few themes in my style.css file. For example, one is "theme-light"
.theme-light {
--color-bg-primary: theme('colors.white');
--color-bg-typing: theme('colors.white');
--color-bg-input: theme('colors.white');
--color-bg-redo: theme('colors.blue.500');
--color-bg-redo-hover: theme('colors.red.500');
--color-bg-nav: theme('colors.red.500');
--color-bg-nav-active: theme('colors.red.500');
--color-text-primary: theme('colors.gray.900');
--color-text-secondary: theme('colors.gray.600');
--color-text-current: theme('colors.gray.900');
--color-text-correct: theme('colors.green.400');
--color-text-wrong: theme('colors.red.400');
--color-text-stats: theme('colors.gray.600');
--color-placeholder-primary: theme('colors.gray.600');
}
And I edited my tailwind.config.js file like so:
module.exports = {
future: {
removeDeprecatedGapUtilities: true,
purgeLayersByDefault: true,
},
purge: [],
theme: {
backgroundColor: {
primary: 'var(--color-bg-primary)',
typing: 'var(--color-bg-typing)',
input: 'var(--color-bg-input)',
redo: 'var(--color-bg-redo)',
'redo-hover': 'var(--color-bg-redo-hover)',
nav: 'var(--color-bg-nav)',
'nav-active': 'var(--color-bg-nav-active)',
},
textColor: {
primary: 'var(--color-text-primary)',
secondary: 'var(--color-text-secondary)',
current: 'var(--color-text-current)',
correct: 'var(--color-text-correct)',
wrong: 'var(--color-text-wrong)',
stats: 'var(--color-text-stats)',
},
placeholderColor: {
primary: 'var(--color-placeholder-primary)',
},
},
variants: {},
plugins: [require('#tailwindcss/typography')],
};
My question is: now I am unable to set anything like I was before in the html (like "text-blue-400" or "text-opacity-50"). How can I get the default configurations working again?
oh lol. all i had to use extend: https://tailwindcss.com/docs/theme

Why are css classes are missing in production when using Tailwind and next.js?

Tailwind version: v9.3.5
PostCSS Config:
// postcss.config.js
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
...(process.env.NODE_ENV === 'production'
? {
'#fullhuman/postcss-purgecss': {
content: ['./components/**/*.js', './pages/**/*.js'],
defaultExtractor: content =>
content.match(/[\w-/:]+(?<!:)/g) || [],
},
}
: {}),
},
}
Tailwind Config:
// tailwind.config.js
module.exports = {
theme: {
extend: {
colors: {
tint: 'rgba(0,0,0,0.3)',
},
},
},
variants: {},
plugins: [],
}
Styles work perfectly in development but in production only some styling is working. Upon checking the CSS file in build folder, looks like some of the CSS classes are not being extracted or possibly purged therefore resulting in partial styling of the app.
EDIT : PurgeCSS version 3.0 add safelist option, replace whitelist
I faced the same problem when i dynamically inject name of some classes into my html template.
I am using nuxt.js/tailwindcss so you need to read the documentary first to solve your problem.
Problem
here's the code who generate the classes missing in production
computed: {
axeY() {
return this.y < 0 ? `-translate-y${this.y}` + ' ' : `translate-y-1` + ' '
},
axeX() {
return this.x < 0 ? `-translate-x${this.x}` : `translate-x-${this.x}`
},
PostCSS will analyse all files into the content table (declaring in the config file), noted that my files doesn't include classes with translate prefix
as you can see, my missing classes are: [translate-x-1,-translate-x-1, translate-y-1, -translate-y-1] ... the number 1 is a variable.
Solution
I need to tell purgecss to not delete those classes by adding them into a whitelist
Or you can use them into your files, for example by creating an unless file (a file analyzed by PostCSS)
You can specify content that should be analyzed by PurgeCSS with an array of filenames
Maintain your config file of TailWindCSS by specifying all cores plugins that you're using
In a complicated case you can use a regular expression in the config file.
in my case, i can directly config purge in the config file of TailWindCSS, by passing the whitelist in the options variable, and here is my config file when i use the first solution :
/*
** TailwindCSS Configuration File
**
** Docs: https://tailwindcss.com/docs/configuration
** Default: https://github.com/tailwindcss/tailwindcss/blob/master/stubs/defaultConfig.stub.js
*/
const num = [1, 2, 3, 4, 5, 6, 8, 10, 12]
const whitelist = []
num.map((x) => {
whitelist.push('translate-x-' + x)
whitelist.push('-translate-x-' + x)
whitelist.push('translate-y-' + x)
whitelist.push('-translate-y-' + x)
})
module.exports = {
future: {
removeDeprecatedGapUtilities: true,
},
theme: {},
variants: {
backgroundColor: ['hover', 'focus', 'active'],
},
plugins: [],
purge: {
// Learn more on https://tailwindcss.com/docs/controlling-file-size/#removing-unused-css
enabled: process.env.NODE_ENV === 'production',
content: [
'components/**/*.vue',
'layouts/**/*.vue',
'pages/**/*.vue',
'plugins/**/*.js',
'nuxt.config.js',
],
options: {
whitelist,
},
},
}
Found the issue, postcss config was missing sections folder in content array and also since my js files had jsx, i need to add that as well.
// postcss.config.js
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
...(process.env.NODE_ENV === 'production'
? {
'#fullhuman/postcss-purgecss': {
// added sections folder and changed extension to jsx
content: ['./components/**/*.jsx', './pages/**/*.js', './sections/**/**/*.jsx'],
defaultExtractor: content =>
content.match(/[\w-/:]+(?<!:)/g) || [],
},
}
: {}),
},
}
I struggled with this same issue. Tailwind will purge classes created with string concatenation.
One solve is to save class names as variables.
n = ‘row-start-2’;
className={n}
For my use case I couldn't do this. Instead, I used the safelist greedy option.
In tailwind config file:
module.exports = {
purge: {
content: ["./pages/**/*.{js,ts,jsx,tsx}", "./components/**/*.{js,ts,jsx,tsx}"],
options: {
safelist: {
greedy: ["/safe$/"],
},
},
},
Then I added the "safe" class to all elements where I'm using string concatenation to create classes.
className={`safe sm:grid-cols-${smCols} sm:grid-rows-${smRows} md:grid-cols-${mdCols} md:grid-rows-${mdRows}

How to get CSS IntelliSense to work on a Nuxt project?

I'm working on a Nuxt.js Project, I created a Docker image as well to handle everything; I'm also trying to include MDBVue as a CSS library, after reading I understand that in order to use this I have to include it as a plugin and reference it on my nuxt.config.js file;
This is how my file looks:
module.exports = {
/*
** Headers of the page
*/
head: {
title: 'skfe',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: 'Nuxt.js project' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
]
},
/*
** Customize the progress bar color
*/
loading: { color: '#3B8070' },
css: [
{ src: "bootstrap-css-only/css/bootstrap.min.css" },
{ src: "mdbvue/build/css/mdb.css" }
],
/*
** Build configuration
*/
build: {
/*
** Run ESLint on save
*/
extend (config, { isDev, isClient }) {
if (isDev && isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/
})
}
}
}
}
Now the CSS classes work, but I'm not able to get any autocompletion from VSCode, I have to type in the full class name; is this normal behavior or is there a way to get IntelliSense to work on my Vue files?
This is the normal behaviour:
https://github.com/Microsoft/vscode/issues/27635
Try the plugin:
IntelliSense for CSS class names in HTML
or
HTML CSS Support
Source: https://code.visualstudio.com/docs/languages/css
And of course Vetur a must-have plugin for vue development in vscode.

Resources