All files / publisher-admin/pages/Publicise PubliciseButtons.tsx

100% Statements 5/5
50% Branches 2/4
100% Functions 3/3
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126              119x 119x   119x                               60x       1785x                                                                                                                                                                                              
import { useState } from "react";
import { useParams } from "react-router-dom";
import { Row, Col } from "@canonical/react-components";
 
import { languages } from "../../utils";
 
function PubliciseButtons() {
  const { packageName } = useParams();
  const [selectedLanguage, setSelectedLanguage] = useState<string>("en");
 
  return (
    <>
      <h2 className="p-heading--4">
        Promote your charm using Charmhub buttons
      </h2>
      <Row>
        <Col size={2}>
          <label htmlFor="language">Language:</label>
        </Col>
        <Col size={7}>
          <div className="p-form--inline">
            <select
              defaultValue={selectedLanguage}
              name="language"
              id="language"
              onChange={(e) => {
                setSelectedLanguage(e.target.value);
              }}
            >
              {Object.keys(languages).map((language) => (
                <option value={language} key={language}>
                  {languages[language].title}
                </option>
              ))}
            </select>
          </div>
        </Col>
      </Row>
 
      <hr className="p-separator--shallower"></hr>
 
      <h3 className="p-heading--4">Dark version</h3>
 
      <Row>
        <Col size={7} className="col-start-large-3">
          <p>
            <a href={`/${encodeURIComponent(packageName || "")}`}>
              <img
                alt=""
                src={`/static/images/badges/${encodeURIComponent(selectedLanguage)}/charmhub-black.svg`}
              />
            </a>
          </p>
        </Col>
      </Row>
      <Row>
        <Col size={2}>
          <p>HTML:</p>
        </Col>
        <Col size={7}>
          <div className="p-code-snippet">
            {/* prettier-ignore */}
            <pre className="p-code-snippet__block is-wrapped"><code>{`<a href="https://charmhub.io/${packageName}">
  <img alt="" src="https://charmhub.io/static/images/badges/${selectedLanguage}/charmhub-black.svg" />
</a>`}</code></pre>
          </div>
        </Col>
      </Row>
      <Row>
        <Col size={2}>
          <p>Markdown:</p>
        </Col>
        <Col size={7}>
          <div className="p-code-snippet">
            {/* prettier-ignore */}
            <pre className="p-code-snippet__block is-wrapped"><code>{`[![${languages[selectedLanguage].text}](https://charmhub.io/static/images/badges/${selectedLanguage}/charmhub-black.svg)](https://charmhub.io/${packageName})`}</code></pre>
          </div>
        </Col>
      </Row>
 
      <hr className="p-separator--shallower"></hr>
 
      <h3 className="p-heading--4">Light version</h3>
 
      <Row>
        <Col size={7} className="col-start-large-3">
          <p>
            <a href={`/${encodeURIComponent(packageName || "")}`}>
              <img
                alt=""
                src={`/static/images/badges/${encodeURIComponent(selectedLanguage)}/charmhub-white.svg`}
              />
            </a>
          </p>
        </Col>
      </Row>
      <Row>
        <Col size={2}>
          <p>HTML:</p>
        </Col>
        <Col size={7}>
          <div className="p-code-snippet">
            {/* prettier-ignore */}
            <pre className="p-code-snippet__block is-wrapped"><code>{`<a href="https://charmhub.io/${packageName}">
  <img alt="" src="https://charmhub.io/static/images/badges/${selectedLanguage}/charmhub-white.svg" />
</a>`}</code></pre>
          </div>
        </Col>
      </Row>
      <Row>
        <Col size={2}>
          <p>Markdown:</p>
        </Col>
        <Col size={7}>
          <div className="p-code-snippet">
            {/* prettier-ignore */}
            <pre className="p-code-snippet__block is-wrapped"><code>{`[![${languages[selectedLanguage].text}](https://charmhub.io/static/images/badges/${selectedLanguage}/charmhub-white.svg)](https://charmhub.io/${packageName})`}</code></pre>
          </div>
        </Col>
      </Row>
    </>
  );
}
 
export default PubliciseButtons;