Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="root"></div>
              
            
!

CSS

              
                /**
 * Design Credit:
 * https://dribbble.com/shots/4241423-Exchanger-landing-page
**/

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Verdana;
  background: rgb(28, 78, 154);
  background: linear-gradient(
    237deg,
    rgba(28, 78, 154, 1) 48%,
    rgba(44, 110, 206, 1) 85%,
    rgba(45, 123, 238, 1) 100%
  );
}

.container {
  display: flex;
  flex-direction: column;
  box-shadow: 1px 1px 10px 1px #333;
  border-radius: 7px;
  background: white;
  min-width: 440px;
  min-height: 320px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
  background-color: #2d7bee;
  color: white;
  font-size: 20px;
}

.card-body {
  flex: 1;
  padding: 30px;
}

.unit-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 45px;
}

.unit {
  display: inline-flex;
  background-color: #2d7bee;
  align-items: center;
  justify-content: center;
  width: 75px;
  height: 35px;
  color: white;
  border-radius: 3px;
}

.exchange-icon {
  color: #a8aeba;
}

.angle-icon {
  color: #b0c9f6;
}

.converter {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.converter-title {
  color: #a8aeba;
  font-weight: bold;
  margin-bottom: 12px;
}

.card-footer {
  min-height: 40px;
  margin: 5px;
  border-bottom-left-radius: 6px;
  border-bottom-right-radius: 6px;
  background-color: #2d7bee;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.input-number {
  font-size: 32px;
  max-width: 170px;
  flex: 1;
  display: inline-block;
  background: transparent;
  border: none;
  outline: none;
  font-family: Courier;
  color: #2d7bee;
  font-weight: bold;
}

.text-right {
  text-align: right;
}
.flex-1 {
  flex: 1;
}
              
            
!

JS

              
                const { useState } = React;

const UnitControl = () => (
  <div className="unit-control">
    <div className="unit">Mbps</div>
    <span className="exchange-icon fa-fw fa-stack">
      <i className="far fa-circle fa-stack-2x" />
      <i className="fas fa-exchange-alt fa-stack-1x" />
    </span>
    <div className="unit">MB/s</div>
  </div>
);

// STEP 2:透過 props 取得從父層傳入的資料
const CardFooter = props => {
  const { inputValue } = props;
  let criteria;

  if (!inputValue) {
    criteria = {
      title: "---",
      backgroundColor: "#d3d8e2"
    };
  } else if (inputValue < 15) {
    criteria = {
      title: "SLOW",
      backgroundColor: "#ee362d"
    };
  } else if (inputValue < 40) {
    criteria = {
      title: "GOOD",
      backgroundColor: "#1b82f1"
    };
  } else if (inputValue >= 40) {
    criteria = {
      title: "FAST",
      backgroundColor: "#13d569"
    };
  }

  return (
    <div
      className="card-footer"
      style={{
        backgroundColor: criteria.backgroundColor
      }}
    >
      {criteria.title}
    </div>
  );
};

const SpeedConverter = () => {
  const [inputValue, setInputValue] = useState(0);

  const handleInputChange = e => {
    const { value } = e.target;
    setInputValue(value);
  };

  return (
    <div className="container">
      <div className="card-header">Network Speed Converter</div>
      <div className="card-body">
        <UnitControl />
        <div className="converter">
          <div className="flex-1">
            <div className="converter-title">Set</div>
            <input
              type="number"
              onChange={handleInputChange}
              value={inputValue}
              className="input-number"
              min="0"
            />
          </div>
          <span
            className="angle-icon fa-2x"
            style={{
              marginTop: 30
            }}
          >
            <i className="fas fa-angle-right" />
          </span>
          <div className="text-right flex-1">
            <div className="converter-title">Show</div>
            <input
              className="input-number text-right"
              type="text"
              value={inputValue / 8}
              disabled
            />
          </div>
        </div>
      </div>
      {/* STEP 1: 把想要傳入 CardFooter 的資料透過 key={value} 的方式傳入 */}
      <CardFooter inputValue={inputValue} />
    </div>
  );
};

ReactDOM.render(<SpeedConverter />, document.getElementById("root"));

              
            
!
999px

Console