Discourse: استخدام 'SVG Icon' و 'Emoji' بسهولة في CSS

<div data-theme-toc="true"> </div>

Hello :wave:

This topic contain two theme component.

Discourse Easy SVG Icon CSS

:warning: This theme component is functional as a template, please fork it on Github or use the code to your project. You can remove the icons svg codes from the SCSS and only keep those what you really actually use… I have imported the mixin file to the common.scss file so you can add your code below that line or separately to the desktop or mobile section.

The theme component add the ability to keep the SVG icon a maintainable and easily editable in your CSS. The component contains the all svg icons found here: discourse/vendor/assets/svg-icons/fontawesome at main · discourse/discourse · GitHub



How to use?

Fix parameters:

$icon-set: brands, regular, solid
$icon-name: icon name
$icon-color: icon color (currentColor, hex or color variable)
$width and $height: the size of the added icon

It looks like this:

@include svg-icon($icon-set, $icon-name, $icon-color, $width, $height);

Using currentColor
Here is an example to adding a solid rocket icon before the Latest navigation bar item.

#navigation-bar {
  li.nav-item {
    &_latest {
      a {      
        gap: 0.5em;
        &:before {
          content: "";
          @include svg-icon(solid, rocket, currentColor, 1em, 1em);
        }
      }
    }
  }
}

add-icon-to-latest


Using var(--gold) color variable
Here is an example to add a regular gold star icon before the Top navigation bar item.

#navigation-bar {
  li.nav-item {
    &_top {
      a {      
        gap: 0.5em;
        &:before {
          content: "";
          @include svg-icon(regular, star, var(--gold), 1em, 1em);
        }
      }
    }
  }
}

add-star-to-top


We can easily change the icon set, the color or even the icon too on hover etc… Let’s see!

Now we change the regular icon to solid when I hover the button.

#navigation-bar {
  li.nav-item {
    &_top {
      a {      
        gap: 0.5em;
        &:hover,
        &:focus,
        &.active {
          &:before {
            @include svg-icon(solid, star, currentColor, 1em, 1em);
          }
        }
        &:before {
          content: "";
          @include svg-icon(regular, star, currentColor, 1em, 1em);
        }
      }
    }
  }
}

change-icon-set


Discourse Easy Emoji CSS

:warning: This theme component is functional as a template, please fork it on Github or use the code to your project. I have imported the mixin file to the common.scss file so you can add your code below that line or separately to the desktop or mobile section.

How to use?

The usage is similar like the SVG version.

Fix parameters:

$emoji-set: apple, google, twitter, win10, google_classic, facebook_messenger
$emoji-name: emoji name
$width and $height: the size of the added emoji

@include emoji($emoji-set, $emoji-name, $width, $height);

Here is an example to adding a facebook_messenger rocket emoji before the Latest and a twitter star emoji before the Top navigation bar item.

#navigation-bar {
  li.nav-item {
    &_latest {
      a {      
        gap: 0.5em;
        &:before {
          content: "";
          @include emoji(facebook_messenger, rocket, 1em, 1em);
        }
      }
    }
    &_top {
      a {      
        gap: 0.5em;
        &:before {
          content: "";
          @include emoji(twitter, star, 1em, 1em);
        }
      }
    }
  }
}

Screenshot 2024-03-25 at 5.26.26

13 إعجابًا

صباح الخير @Don،

لقد كنت أتابع عملك بجد وأعتقد أنني قمت بدمج جميع إبداعاتك في منتداي. ومع ذلك، مع هذا العنصر بالذات، أنا غير متأكد. منذ ترقية الخطاب، أصبح عقلي مشوشًا، ولا أستطيع تذكر مكان تطبيق أكواد CSS هذه. لقد قمت بدمج كود GitHub الخاص بك في السمة، ولكن لا يبدو أن شيئًا يظهر.

إعجاب واحد (1)

أعتقد أن السمة يفترض أن تكون قاعدة قابلة للتعديل لكي تعمل عليها:

مما قد يفسر سبب عدم ظهور أي شيء عند تثبيته، حيث أن القالب من المحتمل أن يفعل القليل أو لا شيء بمفرده.

إعجاب واحد (1)

ألا ينبغي أن يكون هذا مرئيًا لنا؟

أو

لا، نظرًا لأنه سمة بعيدة، مما يعني أنه يجب عليك إما تنزيلها من GitHub وتحميلها كملف مضغوط إلى مثيلك، أو عمل نسخة من مستودع GitHub وإجراء تغييراتك هناك.

إعجاب واحد (1)

بالتأكيد، هذا مفهوم جديد تمامًا بالنسبة لي. ومع ذلك، أتفهم وجهة نظرك؛ كل يوم هو فرصة للتعلم، وأنا أقدر الاستجابة السريعة.

إعجابَين (2)

مرحباً @Aaron_Walsh :waving_hand: هل نجح الأمر معك أخيراً؟ هل هناك حالة استخدام محددة تريد استخدامها فيها؟ إذا شاركت بعض التفاصيل، يمكنني إنشاء مكون سمة منفصل بناءً على هذا حيث يمكن تعديله بسهولة باستخدام الإعدادات.

صباح الخير،

كانت المهمة ستنجح؛ ومع ذلك، لم يعد لدي جهاز كمبيوتر محمول يعمل بنظام Windows لأغراض التحرير. بدلاً من ذلك، انتقلت إلى استخدام Samsung Galaxy S9 Ultra، وهو قرار أجد أنه مؤسف بعض الشيء الآن :sweat_smile:.

توجد طريقة يمكنني من خلالها إنجاز هذه المهمة باستخدام خادم الاستضافة الخاص بي (cPanel) عن طريق التحميل والتحرير. ومع ذلك، يجب أن أشير بأسف إلى أن العمل الذي صاغته قد يكون معقدًا لبعض الأفراد.

لذلك، إذا كنت موافقًا،

9e9f0a12fb60537533c141e18e145f7d98eecb9c

هذا التصميم هو موضوع إعجابي والذي أجذب إليه بشكل خاص!

إعجاب واحد (1)

نعم، هذا هو السبب في وضعه في فئة Dev ولكن لا تقلق، سأقوم بإنشاء Theme component لهذه الحالة. :slightly_smiling_face:

3 إعجابات

اعتذاري، لقد كان ذلك سهوًا مني! ومع ذلك، للمضي قدمًا، سأكون على اطلاع أفضل بهذا الأمر.

مرحباً :waving_hand: تم الانتهاء من #مكون-القالب هذا. :white_check_mark:

أنت رائع! شكرا لك!

إعجاب واحد (1)