npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

posthtml-bootstrap

v1.0.4

Published

A PostHTML plugin that allows you to use Bootstrap components directly in your HTML code

Downloads

108

Readme

posthtml-bootstrap

A PostHTML plugin that allows you to use Bootstrap components directly in your HTML code.

Install

To get started, install the package using npm or yarn:

npm install -D posthtml-bootstrap
# Or
yarn add -D posthtml-bootstrap

Usage

import posthtml from 'posthtml'
import posthtmlComponent from 'posthtml-component'
import { defineBootstrapUIConfig } from 'posthtml-bootstrap'

// Use default configuration
const config = defineBootstrapUIConfig()
// Create a PostHTML processor with the plugin
const processor = posthtml([posthtmlComponent(config)])

// Your HTML with Bootstrap components
const htmlString = `
<ui:container>
  <ui:row>
    <ui:col>
      <ui:button variant="primary">Click me!</ui:button>
    </ui:col>
  </ui:row>
</ui:container>
`

processor
  .process(htmlString, {
    recognizeSelfClosing: true
  })
  .then(result => {
    console.log(result.html) // Processed HTML with Bootstrap components
  })

A wide range of Bootstrap components are available for use with this plugin. You can find the complete list of components in the ui directory.

Note: Detailed documentation for each component is currently under development 😉

Configuration Options

To configure Bootstrap UI, use the following JavaScript snippet:

import { defineBootstrapUIConfig } from 'posthtml-bootstrap'

const config = defineBootstrapUIConfig({
  // Options go here
})

Please refer to the posthtml-component documentation to review the available options.

Opinionated options:

The following options are opinionated and cannot be changed:

  • root: (string) String value as the root path for component lookup. Always process.cwd().
  • tagPrefix: (string) The prefix used for component tags in your HTML. Always ui:.
  • yield: (string) The tag name used for the main content area within a component. Always <children />.
  • attribute: (string) The attribute used to specify the component path within a tag. Always @src.

Extended Components

posthtml-bootstrap allows you to seamlessly integrate your own custom components alongside the built-in Bootstrap components. This is achieved by referencing the folder path containing your custom components in the folders property of the configuration.

  1. Create your custom components:

    Start by creating your custom components as HTML files within a dedicated folder. For example, let's create a components folder and add a simple foo.html component:

    <!-- views/components/foo.html -->
    <div class="foo">This is a custom foo component.</div>
  2. Configure the plugin:

    In your JavaScript file, modify the configuration to include the path to your custom components folder:

    import { defineBootstrapUIConfig } from 'posthtml-bootstrap'
    
    const config = defineBootstrapUIConfig({
      folders: ['views/components'] // Add your custom components folder
    })
  3. Use your custom components:

    Now you can use your custom component in your HTML just like any other Bootstrap component:

    <ui:container>
      <ui:row>
        <ui:col>
          <ui:foo />
        </ui:col>
      </ui:row>
    </ui:container>

Custom Utilities

The utilities option allows you to provide custom functions that can be accessed within the <script props> block of a component.

const config = defineBootstrapUIConfig({
  utilities: {
    formatPrice(price) {
      return new Intl.NumberFormat('en-US', {
        style: 'currency',
        currency: 'USD'
      }).format(+price)
    }
  }
})

Then, use your custom utility function within a component's props script:

<!-- views/components/foo.html -->
<script props>
  const { price } = props

  module.exports = {
    formattedPrice: formatPrice(price)
  }
</script>

<!-- use the formatted price in your component's HTML -->
<p class="foo">The price is: {{formattedPrice}}</p>

Finally, use the ui:foo component like so:

<ui:foo price="1000" />

This will render the formatted price using your custom formatPrice function:

<p class="foo">The price is: $1,000.00</p>

Contributing

We 💛  issues.

When committing, please conform to the semantic-release commit standards. Please install commitizen and the adapter globally, if you have not already.

npm i -g commitizen cz-conventional-changelog

Now you can use git cz or just cz instead of git commit when committing. You can also use git-cz, which is an alias for cz.

git add . && git cz

License

GitHub

A project by Stilearning © 2024.