halfmoonui / halfmoon

Halfmoon is a highly customizable, drop-in Bootstrap replacement. It comes with three built-in core themes, with dark mode support for all themes and components.
https://www.gethalfmoon.com
MIT License
3.04k stars 118 forks source link

TypeScript Support #16

Closed ja1den closed 4 years ago

ja1den commented 4 years ago

I saw in #3 that you aren't planning to add TypeScript support, but it would be awesome if you did. I'm probably going to write some types for my current project, so maybe I'll make a PR when I get time.

This framework is awesome, thanks!

halfmoonui commented 4 years ago

Sure sounds good. If TypeScript support is something that meaningfully improves the framework, a PR would be great.

ja1den commented 4 years ago

I've written the types, but I got stuck when I realized the repo has a number of differences with the package on npm:

Is there a reason the npm module and the GitHub repo are different?

halfmoonui commented 4 years ago

The halfmoon.js file in this repo is meant to be used with a <script> tag, and it auto-initializes the components that require JS. This does not work with JS frameworks that use the virtual DOM, so the file in the npm package has a slight change that addresses this. I couldn't figure out an elegant way of including the npm files in this repo with the last release, so I decided to leave it out for the time being.

Edit After giving it some more thought, I think it is a bit too early for integrating types into the core file. This is mainly because of the following reasons:

I am sorry for any inconveniences.

ja1den commented 4 years ago

That makes sense. Thanks for considering!

lgk-bsw commented 4 years ago

I also would love to have TypeScript support. @Jadie-Wadie Maybe you could constribute to https://github.com/DefinitelyTyped/DefinitelyTyped, so the types could get published under @types/halfmoon. 😇

halfmoonui commented 4 years ago

@lgk-bsw From what I remember, Bootstrap also does something similar, with a separate repo where there are .ts versions of the .js files.

ixahmedxi commented 4 years ago

A "types" folder can be created and then referenced in the types property inside the package.json file. I think this is better than having a separate repo for the typescript definitions as that it will make users not need to install multiple packages. I can help out with creating the definitions.

ja1den commented 4 years ago

I've created DefinitelyTyped/DefinitelyTyped#46789.

lgk-bsw commented 4 years ago

A "types" folder can be created and then referenced in the types property inside the package.json file. I think this is better than having a separate repo for the typescript definitions as that it will make users not need to install multiple packages. I can help out with creating the definitions.

It's pretty common to have a seperate package for the types. And editors like Visual Studio Code will recommend to install @types/halfmoon, so I think it's a good solution. 😊

ja1den commented 4 years ago

My pull request got merged. Install @types/halfmoon for TypeScript support.

halfmoonui commented 4 years ago

@Jadie-Wadie That is awesome! Thank you for the quick work.

MeowningMaster commented 3 years ago

I'm new to typescript, how to import halfmoon css? (snowpack)

MeowningMaster commented 3 years ago

<link href="https://cdn.jsdelivr.net/npm/halfmoon@1.1.1/css/halfmoon-variables.min.css" rel="stylesheet" /> in index.html works, is it fine solution?

ja1den commented 3 years ago

If you're using snowpack, install it with npm and import it like any other module. I'd put it in your index.ts or index.tsx file.

E.g. import 'node_modules/halfmoon/css/halfmoon-variables.min.css';

You might have to fix the path depending on the location of your file.

MeowningMaster commented 3 years ago

thanks