0
votes

I am building an Aurelia app with TypeScript and decided to try out Semantic UI. I followed this question (Aurelia Semantic dropdown) and it helped me install Semantic into Aurelia. It seems that it got installed already built with default theme. Is there a way I can install semantic into Aurelia TypeScript app, then add some custom gulp tasks to build according to my own theme.config? I would like also to override some variables like colors, font sizes etc. After it is built I'd like to use the built version in Aurelia view models (TypeScript) and in my views. How can I achieve that?

1
I also need the answer of your question, wondering have you fixed your problem? - Coder Absolute
@CoderAbsolute look at my answer below - andy250

1 Answers

0
votes

Here is how I solved this:

  1. Installed semantic to some local folder with npm
  2. Copied over the semantic folder and semantic.json to web app root folder (so semantic folder is on the level where I have node_modules and jspm_packages)
  3. Inside semantic.json I specified the list of components I want to include in my app
  4. Inside semantic.json I modified "output" and "clean" paths to match the folders where I serve files from.

The semantic.json:

{
    "base": "semantic",
    "paths": {
        "source": {
            "config": "src/theme.config",
            "definitions": "src/definitions/",
            "site": "src/site/",
            "themes": "src/themes/"
        },
        "output": {
            "packaged": "../dist/semantic",
            "uncompressed": "../dist/semantic/components/",
            "compressed": "../dist/semantic/components/",
            "themes": "../dist/semantic/themes/"
        },
        "clean": "../dist/semantic"
    },
    "permission": false,
    "autoInstall": false,
    "rtl": false,
    "version": "2.2.4",
    "components": [
        "button",
        ...
        "site"
    ]
}
  1. Inside Aurelia's gulp definitions I added semantic build task

The build/tasks/build.js:

var buildSemantic = require('../../semantic/tasks/build');
gulp.task('build-semantic', buildSemantic);
...
gulp.task('build-layout', function (callback) {
    return runSequence(
        'build-html',
        'build-semantic',
        'build-less',
        callback
    );
});
  1. When coding I go into semantic src (e.g. semantic\src\themes\default\globals\site.variables) and modify things in there
  2. Run gulp build-layout
  3. The output is added to my dist folder and I can use it in my views

As for the view models I created some helper components to be used as aurelia attributes e.g. the semantic tooltip:

import {customAttribute, inject} from 'aurelia-framework';
import * as $ from 'jquery';
import '../semantic/semantic.min.js';

@customAttribute('semantic-tooltip')
@inject(Element)
export class SemanticTooltip {
    constructor(private element: HTMLElement) {
    }

    attached() {
        $(this.element).popup();
    }
}

Usage:

<i class="info circle icon" data-content="Sample tooltip" semantic-tooltip></i>