Skip to content

Commit

Permalink
Use ui-awesome packages. (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Mar 18, 2024
1 parent 9c170cb commit 9b725c9
Show file tree
Hide file tree
Showing 32 changed files with 458 additions and 463 deletions.
83 changes: 81 additions & 2 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,86 @@
preset: psr2
preset: psr12
risky: true

version: 8.1

finder:
exclude:
- docs
- tests/_support
- vendor

enabled:
- alpha_ordered_traits
- array_indentation
- array_push
- combine_consecutive_issets
- combine_consecutive_unsets
- combine_nested_dirname
- declare_strict_types
- dir_constant
- empty_loop_body_braces
- fully_qualified_strict_types
- function_to_constant
- hash_to_slash_comment
- integer_literal_case
- is_null
- logical_operators
- magic_constant_casing
- magic_method_casing
- method_separation
- modernize_types_casting
- native_function_casing
- native_function_type_declaration_casing
- no_alias_functions
- no_empty_comment
- no_empty_phpdoc
- no_empty_statement
- no_extra_block_blank_lines
- no_short_bool_cast
- no_superfluous_elseif
- no_unneeded_control_parentheses
- no_unneeded_curly_braces
- no_unneeded_final_method
- no_unset_cast
- no_unused_imports
- no_unused_lambda_imports
- no_useless_else
- no_useless_return
- normalize_index_brace
- php_unit_dedicate_assert
- php_unit_dedicate_assert_internal_type
- php_unit_expectation
- php_unit_mock
- php_unit_mock_short_will_return
- php_unit_namespaced
- php_unit_no_expectation_annotation
- phpdoc_no_empty_return
- phpdoc_no_useless_inheritdoc
- phpdoc_order
- phpdoc_property
- phpdoc_scalar
- phpdoc_singular_inheritdoc
- phpdoc_trim
- phpdoc_trim_consecutive_blank_line_separation
- phpdoc_type_to_var
- phpdoc_types
- phpdoc_types_order
- print_to_echo
- regular_callable_call
- return_assignment
- self_accessor
- self_static_accessor
- set_type_to_cast
- short_array_syntax
- short_list_syntax
- simplified_if_return
- single_quote
- standardize_not_equals
- ternary_to_null_coalescing
- trailing_comma_in_multiline_array
- unalign_double_arrow
- unalign_equals
- union_type_without_spaces

disabled:
- function_declaration
- psr12_braces
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
"php": ">=8.1",
"npm-asset/flag-icons": "^7.1",
"npm-asset/fortawesome--fontawesome-free": "^6.5",
"php-forge/awesome-component": "dev-main",
"php-forge/html": "^0.1",
"sjaakp/yii2-icon": "^1.0",
"ui-awesome/html": "^0.1",
"ui-awesome/html-component": "^0.1",
"ui-awesome/html-helper":"^0.1",
"yii2-extensions/asset-bootstrap5": "^0.1",
"yii2-extensions/bootstrap5": "^0.1",
"yii2-extensions/localeurls": "dev-main",
"yiisoft/config": "^1.4",
"yiisoft/yii2": "^2.0.49 || ^2.2",
"yiisoft/yii2-symfonymailer": "dev-master as 4.0"
"yiisoft/yii2-symfonymailer": "^4.0"
},
"require-dev": {
"codeception/c3": "^2.8",
Expand All @@ -38,7 +39,7 @@
"symfony/process": "^6.3",
"yii2-extensions/debug": "dev-main",
"yii2-extensions/gii": "dev-main",
"yii2-extensions/phpstan": "dev-main"
"yii2-extensions/phpstan": "^0.1"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 3 additions & 3 deletions config/config-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
'$yii2-debug',
'$yii2-gii',
'$yii2-localeurls',
'web/*.php'
'web/*.php',
],
'params' => 'params.php',
'params-console' => [
'$params',
'params-console.php'
'params-console.php',
],
'params-web' => [
'$params',
'params-web.php'
'params-web.php',
],
],
'config-plugin-options' => [
Expand Down
2 changes: 2 additions & 0 deletions config/messages.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This is a configuration file for the [[\yii\console\controllers\MessageController]] console command.
*
Expand Down
30 changes: 18 additions & 12 deletions config/params-web.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// web application settings shared
'common.aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
'@npm' => '@vendor/npm-asset',
'@public' => '@app/public',
'@web' => '@public',
'@runtime' => '@public/runtime',
Expand All @@ -28,33 +28,39 @@
'web.language' => 'en-US',
'web.name' => 'Web application basic',
'web.params' => [
'app.languages.labels' => [
'de-DE' => 'German',
'en-US' => 'English',
'es-ES' => 'Spanish',
'fr-FR' => 'French',
'pt-BR' => 'Portuguese',
'ru-RU' => 'Russian',
'zh-CN' => 'Chinese',
'app.localeurls.languages' => [
'de' => 'de-DE',
'en' => 'en-US',
'es' => 'es-ES',
'fr' => 'fr-FR',
'pt' => 'pt-BR',
'ru' => 'ru-RU',
'zh' => 'zh-CN',
],
'app.mailer.sender' => 'noreply@example.com',
'app.mailer.sender.name' => 'Web application basic',
'app.menu.isguest' => [
[
'label' => 'Home',
'link' => ['/site/index'],
'order' => 0,
'category' => 'app.basic',
],
[
'label' => 'About',
'url' => ['/site/about'],
'link' => ['/site/about'],
'order' => 1,
'category' => 'app.basic',
],
[
'label' => 'Contact',
'url' => ['/contact/index'],
'link' => ['/contact/index'],
'order' => 2,
'category' => 'app.basic',
],
],
'app.menu.islogged' => [],
'icons' => '@npm/fortawesome--fontawesome-free/svgs/{family}/{name}.svg',
'icons' => '@npm/fortawesome--fontawesome-free/svgs/{family}/{name}.svg',
],
'web.request.cookieValidationKey' => 'your-cookie-validation-key',
'web.request.enableCsrfValidation' => true,
Expand Down
1 change: 1 addition & 0 deletions config/web/components.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'app.basic' => [
'class' => PhpMessageSource::class,
'basePath' => '@resource/message',
'sourceLanguage' => 'en',
],
],
],
Expand Down
6 changes: 3 additions & 3 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
use Yiisoft\Config\Modifier\RecursiveMerge;

// comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_DEBUG') || define('YII_DEBUG', false);

if (getenv('YII_ENV')) {
defined('YII_ENV') or define('YII_ENV', getenv('YII_ENV'));
defined('YII_ENV') || define('YII_ENV', getenv('YII_ENV'));
} else {
defined('YII_ENV') or define('YII_ENV', 'prod');
defined('YII_ENV') || define('YII_ENV', 'prod');
}

if (getenv('YII_C3')) {
Expand Down
2 changes: 2 additions & 0 deletions src/Framework/Asset/AppAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Framework\Asset;

use Yii2\Asset\BootstrapAsset;
use Yii2\Asset\BootstrapPluginAsset;
use yii\web\AssetBundle;
use yii\web\YiiAsset;

Expand All @@ -21,6 +22,7 @@ final class AppAsset extends AssetBundle

public $depends = [
BootstrapAsset::class,
BootstrapPluginAsset::class,
YiiAsset::class,
];

Expand Down
129 changes: 41 additions & 88 deletions src/Framework/resource/js/toggle-theme.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,42 @@
/*!
* Color mode toggler for Bootstrap's docs (https://getbootstrap.com/)
* Copyright 2011-2023 The Bootstrap Authors
* Licensed under the Creative Commons Attribution 3.0 Unported License.
*/
(() => {
'use strict'

const getStoredTheme = () => localStorage.getItem('theme')
const setStoredTheme = theme => localStorage.setItem('theme', theme)

const getPreferredTheme = () => {
const storedTheme = getStoredTheme()
if (storedTheme) {
return storedTheme
}

return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
}

const setTheme = theme => {
if (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.setAttribute('data-bs-theme', 'dark')
} else {
document.documentElement.setAttribute('data-bs-theme', theme)
}
}

setTheme(getPreferredTheme())

const showActiveTheme = (theme, focus = false) => {
const themeSwitcher = document.querySelector('#toggle-theme')

if (!themeSwitcher) {
return
}

const themeSwitcherText = document.querySelector('#toggle-theme-text')
const activeThemeIcon = document.querySelector('.theme-icon-active use')
const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`)
const svgOfActiveBtn = btnToActive.querySelector('svg use').getAttribute('href')

// Añade las siguientes líneas para mostrar el icono de verificación en el botón activo.
const activeCheckIcon = btnToActive.querySelector('.check');
activeCheckIcon.classList.remove('d-none');

document.querySelectorAll('[data-bs-theme-value]').forEach(element => {
const checkIcon = element.querySelector('.check');
if (element === btnToActive) {
checkIcon.classList.remove('d-none');
} else {
checkIcon.classList.add('d-none');
}
element.classList.remove('active')
element.setAttribute('aria-pressed', 'false')
})

btnToActive.classList.add('active')
btnToActive.setAttribute('aria-pressed', 'true')
activeThemeIcon.setAttribute('href', svgOfActiveBtn)
const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})`
themeSwitcher.setAttribute('aria-label', themeSwitcherLabel)

if (focus) {
themeSwitcher.focus()
}
}

window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
const storedTheme = getStoredTheme()
if (storedTheme !== 'light' && storedTheme !== 'dark') {
setTheme(getPreferredTheme())
}
})

window.addEventListener('DOMContentLoaded', () => {
showActiveTheme(getPreferredTheme())

document.querySelectorAll('[data-bs-theme-value]')
.forEach(toggle => {
toggle.addEventListener('click', () => {
const theme = toggle.getAttribute('data-bs-theme-value')
setStoredTheme(theme)
setTheme(theme)
showActiveTheme(theme, true)
})
})
})
})()
'use strict';

const getStoredTheme = () => localStorage.getItem('theme');
const setStoredTheme = theme => localStorage.setItem('theme', theme);

const setTheme = theme => {
document.documentElement.setAttribute('data-bs-theme', theme);
};

const showActiveTheme = (theme, focus = false) => {
const themeToggle = document.querySelector('#theme-toggle');
const moonIcon = themeToggle.querySelector('#theme-dark-icon');
const sunIcon = themeToggle.querySelector('#theme-light-icon');

if (!themeToggle || !moonIcon || !sunIcon) {
return;
}

if (theme === 'dark') {
moonIcon.classList.remove('d-none');
sunIcon.classList.add('d-none');
} else {
moonIcon.classList.add('d-none');
sunIcon.classList.remove('d-none');
}
};

window.addEventListener('DOMContentLoaded', () => {
const storedTheme = getStoredTheme() || 'auto';
setTheme(storedTheme);
showActiveTheme(storedTheme);

document.getElementById('theme-toggle').addEventListener('click', () => {
const currentTheme = getStoredTheme();
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
setStoredTheme(newTheme);
setTheme(newTheme);
showActiveTheme(newTheme);
});
});
})();

0 comments on commit 9b725c9

Please sign in to comment.