项目作者: Jiab77

项目描述 :
Adds Dark Theme selector and auto-detection logic to Fomantic-UI
高级语言: JavaScript
项目地址: git://github.com/Jiab77/dark-fomantic-ui.git
创建时间: 2020-04-04T22:36:40Z
项目社区:https://github.com/Jiab77/dark-fomantic-ui

开源协议:MIT License

下载


dark-fomantic-ui

Adds Dark Theme selector and system theme auto-detection logic to Fomantic-UI

Configuration

Just edit the following variables in dark-fomantic-ui.js:

  1. var $themeElements = [
  2. { name: 'lists', target: $('.ui.list').not('.inverted') },
  3. { name: 'dividers', target: $('.ui.divider').not('.inverted') },
  4. { name: 'dividingHeaders', target: $('.ui.dividing.header').not('.inverted') },
  5. { name: 'iconHeaders', target: $('.ui.icon.header').not('.inverted') },
  6. { name: 'icons', target: $('.icon').not('.inverted') },
  7. { name: 'headers', target: $('.ui.header').not('.inverted') },
  8. { name: 'forms', target: $('.ui.form').not('.inverted') },
  9. // { name: 'tooltippedIcons', target: $('.tooltipped.icon') },
  10. { name: 'cardsContainer', target: $('.ui.cards') },
  11. { name: 'cards', target: $('.ui.card') },
  12. { name: 'dropdowns', target: $('.ui.dropdown') },
  13. { name: 'fixedMenu', target: $('.ui.top.fixed.menu') },
  14. { name: 'breadcrumb', target: $('.ui.breadcrumb') },
  15. { name: 'accordions', target: $('.ui.accordion').not('.styled').not('.inverted') },
  16. { name: 'tables', target: $('.ui.table') },
  17. { name: 'modals', target: $('.ui.modal').not('.inverted') },
  18. { name: 'segments', target: $('.ui.segment').not('.inverted') },
  19. { name: 'placeholders', target: $('.ui.placeholder') }
  20. ];
  21. var $themeValue = $('#theme-value');
  22. var $darkThemeButton = $('div.right.menu div#dark-theme');
  23. var $lightThemeButton = $('div.right.menu div#light-theme');

Where $themeElements array contains all DOM elements that will be styled and get the inverted class applied to.

Each elements objects have two properties:

  1. name: Unique name to distinguish your DOM element
  2. target: The target jquery DOM element

The other variables, $themeValue, $darkThemeButton and $lightThemeButton are used that way:

  • $themeValue: DOM element where the current theme value will be written
  • $darkThemeButton: DOM element that will activate the dark theme
  • $lightThemeButton: DOM element that will activate the light theme

Setup

To include the code in your project, simply add it after your Fomantic UI inclusion line:

  1. ...
  2. <!-- Fomantic-UI -->
  3. <script type="text/javascript" id="jquery-js" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
  4. <script type="text/javascript" id="fomantic-ui-js" src="https://cdnjs.cloudflare.com/ajax/libs/fomantic-ui/2.8.5/semantic.js" integrity="sha256-SeNU96at0t5XRuSk9/cLHWCGC0Ju5pug2NRGXeJCQN4=" crossorigin="anonymous"></script>
  5. <!-- Including Dark Theme -->
  6. <script type="text/javascript" id="dark-ui-js" src="dark-fomantic-ui.js"></script>

Auto-detection

The system theme auto-detection feature is based on window.matchMedia and @media/prefers-color-scheme">prefers-color-scheme.

Screenshots

Here are some screenshots to show how to enable the Dark Mode.

Activation buttons

Light:

image

Dark:

image

There is a small toggle animation when moving over the buttons.

Sample results

From the Nmap WebUI project.

Light theme:

image

Dark theme:

image

Thanks

I just wanted to give a huge thanks to the Fomantic UI team for their amazing work!

Contact