Repository: Appsilon/py_shiny_semantic (language: python)

Issue:
[Elements] Emoji



Discussion / hints:

Fix patch:
diff --git a/app.py b/app.py
index 418f3bd..f4f42bf 100644
--- a/app.py
+++ b/app.py
@@ -3,7 +3,7 @@
 from shiny import App, reactive, render, ui
 
 from shiny_semantic import page_semantic
-from shiny_semantic.elements import button, update_button
+from shiny_semantic.elements import button, emoji, update_button
 
 app_ui = page_semantic(
     ui.tags.div(
@@ -101,6 +101,33 @@
         ),
         class_="ui raised padded container segment",
     ),
+    ui.tags.div(
+        ui.tags.h2("Emoji", class_="ui centered header"),
+        ui.tags.h3("Different sets", class_="ui header"),
+        emoji(emoji_name="smile"),
+        emoji(emoji_name="angry"),
+        emoji(emoji_name="bee"),
+        emoji(emoji_name="blowfish"),
+        emoji(emoji_name="apple"),
+        emoji(emoji_name="avocado"),
+        emoji(emoji_name="badminton"),
+        emoji(emoji_name="dart"),
+        emoji(emoji_name="airplane"),
+        ui.tags.h3("Skin tones", class_="ui header"),
+        emoji("adult"),
+        emoji("adult_tone1"),
+        emoji("adult_tone2"),
+        emoji("adult_tone3"),
+        emoji("adult_tone4"),
+        emoji("adult_tone5"),
+        ui.tags.h3("Sizes", class_="ui header"),
+        emoji("flag_pl", class_name="tiny"),
+        emoji("flag_pl", class_name="small"),
+        emoji("flag_pl", class_name="medium"),
+        emoji("flag_pl", class_name="large"),
+        emoji("flag_pl", class_name="big"),
+        class_="ui raised padded container segment",
+    ),
     title="Example: Buttons",
 )
 
diff --git a/shiny_semantic/elements/__init__.py b/shiny_semantic/elements/__init__.py
index fbce1b3..36ea6c7 100644
--- a/shiny_semantic/elements/__init__.py
+++ b/shiny_semantic/elements/__init__.py
@@ -2,6 +2,8 @@
 __all__ = (
     "button",
     "update_button",
+    "emoji",
 )
 
 from .button import button, update_button
+from .emoji import emoji
diff --git a/shiny_semantic/elements/emoji.py b/shiny_semantic/elements/emoji.py
new file mode 100644
index 0000000..c54ca54
--- /dev/null
+++ b/shiny_semantic/elements/emoji.py
@@ -0,0 +1,10 @@
+from typing import Optional
+
+from shiny.ui import tags
+
+
+def emoji(
+    emoji_name: str,
+    class_name: Optional[str] = "medium",
+):
+    return tags.em({"data-emoji": f":{emoji_name}:", "class": class_name})


Test patch:
diff --git a/tests/test_emoji.py b/tests/test_emoji.py
new file mode 100644
index 0000000..f1bd363
--- /dev/null
+++ b/tests/test_emoji.py
@@ -0,0 +1,29 @@
+import unittest
+
+from shiny import App
+
+from shiny_semantic import page_semantic
+from shiny_semantic.elements import emoji
+
+
+class TestEmoji(unittest.TestCase):
+    def test_emoji(self):
+        test_case_1 = '<em data-emoji=":adult:" class="medium">'
+        test_case_2 = '<em data-emoji=":adult:" class="big">'
+
+        app = App(
+            page_semantic(
+                emoji("adult"),
+                emoji("adult", class_name="big"),
+            ),
+            None,
+        )
+
+        html = app.ui.get("html")
+
+        self.assertTrue(test_case_1 in html)
+        self.assertTrue(test_case_2 in html)
+
+
+if __name__ == "__main__":
+    unittest.main()