SettingsApi.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import styled, { css } from 'styled-components';
  4. import Button from '../Button';
  5. const Wrapper = styled.div`
  6. display: flex;
  7. flex-direction: column;
  8. align-items: flex-start;
  9. `;
  10. const ApiKeyWrapper = styled.div`
  11. display: flex;
  12. align-items: center;
  13. margin: 16px 0;
  14. button {
  15. margin-right: 16px;
  16. }
  17. ${({ apikey }) =>
  18. apikey &&
  19. css`
  20. flex-direction: column;
  21. align-items: flex-start;
  22. > span {
  23. margin-bottom: 32px;
  24. }
  25. `};
  26. @media only screen and (max-width: 768px) {
  27. width: 100%;
  28. overflow-wrap: break-word;
  29. }
  30. `;
  31. const ApiKey = styled.span`
  32. max-width: 100%;
  33. font-size: 18px;
  34. font-weight: bold;
  35. border-bottom: 2px dotted #999;
  36. @media only screen and (max-width: 768px) {
  37. font-size: 14px;
  38. }
  39. `;
  40. const Link = styled.a`
  41. margin: 16px 0;
  42. @media only screen and (max-width: 768px) {
  43. margin: 8px 0;
  44. }
  45. `;
  46. const SettingsApi = ({ apikey, generateKey, loader }) => (
  47. <Wrapper>
  48. <h3>API</h3>
  49. <p>
  50. In additional to this website, you can use the API to create, delete and get shortend URLs. If
  51. {"you're"} not familiar with API, {"don't"} generate the key. DO NOT share this key on the
  52. client side of your website.
  53. </p>
  54. <ApiKeyWrapper apikey={apikey}>
  55. {apikey && <ApiKey>{apikey}</ApiKey>}
  56. <Button color="purple" icon={loader ? 'loader' : 'zap'} onClick={generateKey}>
  57. {apikey ? 'Regenerate' : 'Generate'} key
  58. </Button>
  59. </ApiKeyWrapper>
  60. <Link href="http://github.com/thedevs-network/kutt#api" title="API Docs" target="_blank">
  61. Read API docs
  62. </Link>
  63. </Wrapper>
  64. );
  65. SettingsApi.propTypes = {
  66. apikey: PropTypes.string.isRequired,
  67. loader: PropTypes.bool.isRequired,
  68. generateKey: PropTypes.func.isRequired,
  69. };
  70. export default SettingsApi;