Advertisement
Guest User

Untitled

a guest
Jan 1st, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns pokedex.view.info-card
  2.   (:require
  3.    [clojure.string :as s]
  4.    ["react-native" :as rn]))
  5.  
  6. (def styles
  7.   {:info-card {:flex 1
  8.                :flex-direction :row
  9.                :justify-content :space-between
  10.                :align-items :center
  11.                :padding 15
  12.                :margin-horizontal 10
  13.                :border-radius 15
  14.                :height 100}
  15.    :info-view {:flex 0.75
  16.                :justify-content :center
  17.                :align-items :flex-start
  18.                :padding 5
  19.                :height 100}
  20.    :txt-view {:flex-grow 1
  21.               :flex-direction :row
  22.               :align-items :center}
  23.    :name {:font-size 22
  24.           :margin-horizontal 10}
  25.    :id {:font-size 22
  26.         :opacity 0.4}
  27.    :type-view {:flex-grow 1
  28.                :flex-direction :row
  29.                :justify-content :space-between
  30.                :align-items :center}
  31.    :small-txt {:font-size 16
  32.                :border-width 2
  33.                :border-radius 10
  34.                :opacity 0.6
  35.                :padding-horizontal 10
  36.                :padding-vertical 3
  37.                :margin-horizontal 5}
  38.    :img-view {:flex 0.25
  39.               :width 100
  40.               :height 100
  41.               :justify-content :center
  42.               :align-items :center}
  43.    :img (let [safepad 10]
  44.           {:width (- 100 safepad)
  45.            :height (- 100 safepad)})})
  46.  
  47. (def type->colour
  48.   {"unknown" "#68a090"
  49.    "bug" "#a8b820"
  50.    "dark" "#705848"
  51.    "dragon" "#7038f8"
  52.    "electric" "#f8d030"
  53.    "fairy" "#ee99ac"
  54.    "fighting" "#c03028"
  55.    "fire" "#f08030"
  56.    "flying" "#a890f0"
  57.    "ghost" "#705898"
  58.    "grass" "#78c850"
  59.    "ground" "#e0c068"
  60.    "ice" "#98d8d8"
  61.    "normal" "#a8a878"
  62.    "poison" "#a040a0"
  63.    "psychic" "#f85888"
  64.    "rock" "#b8a038"
  65.    "steel" "#b8b8d0"
  66.    "water" "#6890f0"})
  67.  
  68. (defn- render-id [id]
  69.  (cond
  70.   (>= id 100) (str "#" id)
  71.   (>= id 10) (str "#0" id)
  72.   :else (str "#00" id)))
  73.  
  74. (defn- text-data [id name]
  75.   [:> rn/View {:style (:txt-view styles)}
  76.    [:> rn/Text {:style (:id styles)} (render-id id)]
  77.    [:> rn/Text {:style (:name styles)} (s/capitalize name)]])
  78.  
  79. (defn- type-container [types]
  80.   (->> types
  81.        (map (fn [t]
  82.               [:> rn/Text
  83.                {:style (:small-txt styles)}
  84.                (:name (:type t))]))
  85.        (into [:> rn/View
  86.               {:style (:type-view styles)}])))
  87.  
  88. (defn- image [style sprites]
  89.   [:> rn/View style
  90.    [:> rn/Image
  91.     {:style (:img styles)
  92.      :source {:uri (:front_default sprites)}}]])
  93.  
  94. (defn mod-style [index type style-map]
  95.   (cond-> style-map
  96.     (zero? index) (assoc :margin-top 10)
  97.     true (assoc :background-color (type->colour type))))
  98.  
  99. (defn info-card [{:keys [id index name types sprites]}]
  100.   [:> rn/View {:style (mod-style index
  101.                                  (first (map (comp :name :type) types))
  102.                                  (:info-card styles))}
  103.    [:> rn/View {:style (:info-view styles)}
  104.     [text-data id name]
  105.     [type-container types]]
  106.    [image {:style (:img-view styles)} sprites]])
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement