File size: 1,022 Bytes
3223525
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import type { Config, DriveStep } from "driver.js";
import { driver } from "driver.js";
import "driver.js/dist/driver.css";

type CodeSampleProps = {
  heading: string;

  config?: Config;
  highlight?: DriveStep;
  tour?: DriveStep[];

  id?: string;
  className?: string;
  children: any;
};

export function CodeSample(props: CodeSampleProps) {
  const { heading, id, children, className, config, highlight, tour } = props;

  function onClick() {
    if (highlight) {
      const driverObj = driver();
      driverObj.highlight(highlight);
    } else if (tour) {
      const driverObj = driver({
        ...config,
        steps: tour,
      });
      driverObj.drive();
    }
  }

  return (
    <div id={id} className={className}>
      <p className="text-lg -mt-0 font-medium text-black -mb-3 rounded-md">{ heading }</p>
      <div className="-mb-4">{children}</div>
      <button onClick={onClick} className="w-full rounded-md bg-black p-2 text-white">
        Show me an Example
      </button>
    </div>
  );
}